React without memo

Channel:React Conf · Length:12:01 · Published:2021-12-09 · Views:150212

Watch on YouTube

Summary

A React Conf talk by Xuan Huang previewing React Forget, a compiler that automatically memoizes components. It argues for making memoization the default so developers need not write useMemo or useCallback by hand.

Why HN recommends it

Shared in discussions of useCallback and memoization as the first look at where React was heading with an auto-memoizing compiler.

I wanted to share this talk given at a recent React Conf — HN, 2022

Web development · Software performance & optimization · Compilers, interpreters & program analysis

Subtitles (excerpt)

(electronic music) - Hey, what's up folks? I'm Xuan. I'm a Software engineer at Meta. So today, I wanna talk about React and memoization. Here I have yet another TodoList. You know as JavaScript developers we just really, really love TodoLists. So, we enjoy the simplicity of the React code here, until we will open up the Java tools and we realize whenever we add a todo, or talk about todo, all the added todo is actually getting rerendered as well. The badge here shows how many times each todo has been rerendered. To fix this, what we usually do is to wrap the to-do component in React to memo. (keyboard clicks) But don't forget the handleChange is recreated on every render. So we're better also wrap that in useCallback. Now, when we add a todo, or toggle a todo, no other todos are getting rerendered. That's fixed. But, this is going to be a moving target as the app scales up. So later, we wanna build an even better TodoList. First, we wanna pass down visibility prop, so we can use it to call getfiltered functions to filter our TodoList. Then we needed a second prop, then the themeColor, so users can pick a color to theme their user interface. If we try this code out, it works, but the app feels pretty laggy

On Hacker News

For those pushing back, I wanted to share this talk given at a recent React Conf: [VIDEO] The idea (still just an internal prototype) is that one day your compiler might automatically memoize all React components and intermediate values for you. It obviously would be great to skip all the syntax noise, as well as the linter-enforced rules around correctly maintaining dependency arrays, etc. But I… — brundolf, 2022-08
There isn't much info out there yet, but this video is a small preview: [VIDEO] The latest update is mentioned in the March 2023 blog post: [LINK] — matvp, 2023-05
I agree that the typescript team should consider using the compiler to extend javascript rather than just supplement it with types. Like you said, there are technically parts of typescript that don't have a direct corollary in js (enums/namespaces), so why not take it a step further and add some of the features that js is missing? The only example where they've really taken that next step is with… — ksbrooksjr, 2022-10

Related videos