<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Tslint on Maarten on IT</title><link>https://maarten.mulders.it/categories/tslint/</link><description>Recent content in Tslint on Maarten on IT</description><generator>Hugo</generator><language>en-us</language><copyright>&amp;copy; 2013 - 2026 Maarten Mulders</copyright><lastBuildDate>Mon, 27 Sep 2021 21:26:41 +0200</lastBuildDate><atom:link href="https://maarten.mulders.it/categories/tslint/index.xml" rel="self" type="application/rss+xml"/><item><title>No bind or arrow functions in in JSX Props - Why? How?</title><link>https://maarten.mulders.it/2017/07/no-bind-or-arrow-functions-in-in-jsx-props-why-how/</link><pubDate>Tue, 25 Jul 2017 07:30:45 +0200</pubDate><guid>https://maarten.mulders.it/2017/07/no-bind-or-arrow-functions-in-in-jsx-props-why-how/</guid><description>&lt;p&gt;Recently, I found myself running &lt;a href="https://palantir.github.io/tslint/"&gt;tslint&lt;/a&gt; on a small React application written in TypeScript.
The combination itself is worth writing another blog post about, but today we&amp;rsquo;re covering just one of the rules that tslint has; in fact, it is defined in the &amp;ldquo;tslint-react&amp;rdquo; rule set.
It is also included in the &lt;a href="https://github.com/yannickcr/eslint-plugin-react"&gt;eslint-plugin-react&lt;/a&gt;, because it is not related to TypeScript per se.&lt;/p&gt;
&lt;h3 id="whats-it-about"&gt;What&amp;rsquo;s it about?&lt;/h3&gt;
&lt;p&gt;In its ES6 version, the rule says: &amp;ldquo;No &lt;code&gt;.bind()&lt;/code&gt; or Arrow Functions in JSX Props (react/jsx-no-bind).&amp;rdquo;
The TypeScript version has two rules, one is called &amp;ldquo;jsx-no-bind&amp;rdquo; and the other one &amp;ldquo;jsx-no-lambda&amp;rdquo;; their intent is the same as the ES6 one.
When you first notice the rule, you might wonder &amp;ldquo;why is that an issue?&amp;rdquo;.
If you call &lt;code&gt;bind()&lt;/code&gt;, or if you define an arrow function, this will create a brand new function every time you run that code.
When you&amp;rsquo;re using that inside a &lt;code&gt;render()&lt;/code&gt; method or a so-called &lt;a href="https://hackernoon.com/react-stateless-functional-components-nine-wins-you-might-have-overlooked-997b0d933dbc"&gt;stateless functional component&lt;/a&gt;, it will create a new function &lt;em&gt;every time&lt;/em&gt; you render that component.
That violates the &lt;a href="https://facebook.github.io/react/docs/components-and-props.html#props-are-read-only"&gt;one strict rule&lt;/a&gt; from React that says&lt;/p&gt;</description></item></channel></rss>