Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid re-creating functions on every render #10

Merged
merged 1 commit into from Oct 21, 2017
Merged

Avoid re-creating functions on every render #10

merged 1 commit into from Oct 21, 2017

Conversation

@c-w
Copy link
Contributor

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

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
Owner

@shreyas-a shreyas-a commented Oct 21, 2017

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
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants