19

Reading through React - Basic Theoretical Concepts and the upcoming React Fiber Architecture, it seems memoization plays an important central part in the React data handling logic along with immutable data stores.
However, what is not immediately obvious is whether and to what extent is memoization handled internally by React and if and when should a developer memoize manually?

Shortly put, when does React internally memoize function calls and when should a developer do so themselves? Does React memoize any non-internal function calls automatically at all?

1
  • 1
    I don't know the answer to this question, but I've found my manual memoization is greatly sped up in react/redux code when using immutable.js objects, as you only have to compare the immutable.js-provided hash of objects instead of their values. Commented Aug 16, 2016 at 21:51

1 Answer 1

13

React will not do the kind of memoization show in your example, React - Basic Theoretical Concepts. That is up to you.

The best place to do memoization is when you are building your components props. Ie if you have state -> props -> components. You can memoize the mapping from state to props.

If you need the performance gains you get with memoization, and you are thinking of using redux, the reselect docs are a good place to start.

If you go down this road, another large performance gain will come if you also do shallow prop checking in your shouldComponentUpdate function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.