Skip to content

Avoid re-creating functions on every render - #10

Merged
shreyas-a merged 1 commit into
shreyas-a:masterfrom
c-w:avoid-recreating-functions
Oct 21, 2017
Merged

Avoid re-creating functions on every render#10
shreyas-a merged 1 commit into
shreyas-a:masterfrom
c-w:avoid-recreating-functions

Conversation

@c-w

@c-w c-w commented Oct 20, 2017

Copy link
Copy Markdown
Contributor

Previously, the project created anonymous or new functions via bind inside of several render methods. This is hard for React to optimize since the function references will change on every tick of the component life-cycle i.e, React will have to assume that the component changed and re-render it on every cycle which leads to poor performance.

One clean way to solve the this-context and anonymous functions problem at the same time is to use methods at the class level which will automatically preserve the correct this-context while also being constant method references i.e., easy for React to optimize.

You can learn more about this approach in this great article by FreeCodeCamp.

Previously, the project created anonymous or new functions via bind
inside of several render methods. This is hard for React to optimize
since the function references will change on every tick of the component
life-cycle i.e, React will have to assume that the component changed and
re-render it on every cycle which leads to poor performance.

One clean way to solve the this-context and anonymous functions problem
at the same time is to use methods at the class level which will
automatically preserve the correct this-context while also being
constant method references i.e., easy for React to optimize.

You can learn more about this approach here:
https://medium.freecodecamp.org/react-binding-patterns-5-approaches-for-handling-this-92c651b5af56
@shreyas-a

Copy link
Copy Markdown
Owner

Thank you for the PR. Also, the explanation & article is helpful.

@shreyas-a
shreyas-a merged commit 1b19f3b into shreyas-a:master Oct 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants