React Compiler and exhaustive-deps
eslint-plugin-react-no-manual-memo: ESLint plugin for React Compiler users to flag any usage of useMemo, useCallback, and React.memo
[eslint-plugin-react-compiler] eslint-plugin-react-compiler is not compatible with eslint 9 (Flat config)
React Compiler Setup [Experimental] - Experimental Features - RedwoodJS Community
Videos
Hey, guys! I’ve been testing the React Compiler Eslint plugin to see if my codebase could benefit from any changes ahead of React 19 stable. One problem that I’ve run into is that disabling exhaustive-deps inline throws an eslint error because I’m disabling a react eslint rule, implying that the component will be skipped for compiler optimization. However, if I disable the rule globally in my eslintrc, no error is thrown. This might just be a limitation of the linter.
My question is, if I disable this rule globally, will react compiler still refuse to optimize the components that don’t follow the rules of exhaustive-deps? Exhaustive-deps is a rule that I don’t think has historically been the best option, because there are cases when you want to only run a useEffect on mount, and not if the states inside them change. Or, sometimes you only want useEffect to run when some states change, but not when others change.
It could also be the case that I just don’t understand how to write good useEffects after 5 years of using them, so I’m open to feedback about other ways of achieving the goals outlined above in an elegant way.
» npm install eslint-plugin-react-hooks
As someone who learned React in 2022, I write memoization hooks basically by instinct at this point, and I needed something to tell me to stop doing that now that React Compiler is here and tells us to not do that any more.
So, I wrote a little ESLint plugin to catch when I write useMemo, useCallback, or React.memo, and I figured I'd share it with everyone else too. Enjoy!
p.s. I made sure to include React Compiler Playground links in the docs so you can see React Compiler's memoization in action—not just blindly trust that the rules are right!
» npm install eslint-plugin-react-compiler