3 ms·
So why is barData being recomputed? Does anyone understand how React compiler works enough to answer this?
by throwthrow0987 2y ago
So why is barData being recomputed? Does anyone understand how React compiler works enough to answer this?
- acemarke 2y agoYou can see exactly what the React compiler output is by pasting the listed code into the compiler playground: - https://playground.react.dev/#N4Igzg9grgTgxgUxALhAMygOzgFwJYSYAEAQlDjoQBTBEAmAhjgwDRE4IAeObhAwgBs8cANZEAvslLlKmAAowIABzABKIsAA6xInEKQBCAHQCIAcyoADMhUJEAJMA7dxl1QG5t2okRgIcsMRU3j5EADwARjJ2+DiGALzAjMxGsYbiRPxCoolZwiLiAHwhoRrOOOIl4QD0UbaYxToe2pWY2nqYYDhEeNh+ALYImN3xRFQAblKYUP0RCDDq8YVE40QA1EQAjJ5tmBjY+HYAgkpKVOpaOh1dRADaaBAQbL1wfgxgCABijwC6RKNQD4AJQQdCgiBgVBeAyGPCIAAZmld9N1bhEGDBnn0EO8ECQMX8AcDQeD5lDsYNhmxETsQtcIIYTOZgiATkpNCAkXSUUQHhAACJMBj-IiAhAAWQQ-QgVHO-2Wl1K9MZpgsHL5guYHKRpT8ARgxFoaQQUksAEkwFJHHzXBIdj5xGx7r8ucjOt10TBNcKiRKpTK5UsNFVlcZVSzPd7tfbQnrAhp2Hg4iaiObLQ5gJ7beIY467p6fq6fHGDWMqmFGqUfGEbLJ2FwcPF1Y8OfQhYkNUKMnkcsBoTiPt8IBlqpWqzXosRyk2QJ7W8kGIlI13MphBPlEv3cfiYCOx9XRyEka0QOIgA https://playground.react.dev/#N4Igzg9grgTgxgUxALhAMygOzgFwJY... In this case, it looks like the compiler has hoisted the console logs from the `useMemo` calls out into the main body of the function component, because it considers those to be side effects. So, the logs are still occurring. However, the actual child component output _is_ being memoized as expected.