Skip to content

React compiler generates different results based on the return statement #51

Discussion options

You must be logged in to vote

There's a couple of things here:

  1. React Compiler by default only compiles hooks or functions, so if you were to look at your example code in a real repo neither would be compiled since they are not hooks. Our playground however was configured to compile everything. I've fixed that in facebook/react#32009
  2. The compiler only memoizes values that "escape" a component or hook. One of our goals with the compiler is to bound how much rendering can happen. In order to do that we determine which values are used in rendering, and we memoize only those values (and other values that flow into those escaping values). In other words it's not our goal to memoize every single value possible.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@MrFlashAccount
Comment options

Answer selected by MrFlashAccount
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants