Memoization of collection items #58
JeremyGoodwinKaizen
started this conversation in
Feature Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi all,
First off, thanks for amazing work on React Compiler. I have been using it for the past couple of months and it's doing a much better job than me if I were to do it manually!
The React team have probably already thought about this, but I've not seen it mentioned anywhere. Are there any plans to help memoize individual items of a collection?
Take the following code:
https://playground.react.dev/#N4Igzg9grgTgxgUxALhHCA7MAXABAIQEsBzAFQEMAjAGwVwF5cAKASgYD5dgAdDXXdFjwwIAdzANcUMAgBKYsKwDcvfjATZYfADwUaCdqv5cR4gHQBbcgAcmpjsyPHc27DEN9nx1wBN2wUzMMcgsEAF9tAHpsPycvMwTqCGwJCwh1AQRqajAEszj+KLcPZxYWMKMovVp2FQwwkDCgA
React Compiler memoizes the value of
rows
(the entire collection) which is great, but even if a single row changes, the entire table is re-rendered.A manual solution to this problem is to extract the row in to it's own component:
https://playground.react.dev/#N4Igzg9grgTgxgUxALhHCA7MAXABAIQEsBzAFQEMAjAGwVwF5cAKASgYD5dgAdDXXdFjwwIAdzANcUMAgBKYsKwDcvfjATZYfADwUaCdqv5cR4gHQBbcgAcmpjrm3zRuANYIAnvWCmzhACYAvrim3qbBAPTsLIFG2hF6tOwqGLEYvII4uM6SdmJs9Jw8fCEaWo7YMIYl-NrY-uw+YmYY5BYIgfH11ca4Zv3UENgSFhDqAgjU1GD9ZnERldVpIIFAA
Now rows which haven't changed won't get traversed.
I was thinking it would incredibly neat if React Compiler could do something like this automatically. I find myself often writing and preferring code like my first example which has the entire table within one component, and it would be awesome if it could be as efficient as my second example.
Cheers!
Beta Was this translation helpful? Give feedback.
All reactions