What is React compiler ?




3 assumptions
- Code is valid JavaScript
- Test values / properties are defined before acceessing them
- Code follows Rules of React
React Compiler will most likely detect that and skip compilation for the component.
There is alose ESLint plugin that can warn you about potential problems.
How does the compilation work ?
- unoptimized code
const Movies = (...) => {
...
const favoriateMovies = findFavoriteMovies(movies, person);
return (
<MoviesList items={favoriteMovies}/>
)
}
- optimized code
const Movies = (...) => {
const favoriteMovies = useMemo(() => {
return findFavoriteMovies(movies, person)
}, [movies, person])
return (
<MoviesList items={favoriteMovies}/>
)
}
with React Compiler, we don't need to do that anymore, So what exactly does the compiler do in this cases?
It doesn't use useMemo or useCallback at all, Instead, the compiler manualy caches the values and
resuses them if dependencies stay the same.
🚨Do we need to manually memoize anything ?

What about useMemo and useCallback ?


学而不思则罔,思而不学则殆!

浙公网安备 33010602011771号