The app that I work on is having an issue with using non-memoized versions of reference types such as arrays, objects, and functions (see Object & array dependencies in the React useEffect Hook). At the moment I am going through all of our code and manually fixing the issues, however this is not an ideal long-term solution for preventing developers from making the same mistake in the future.
I am investigating ways to prevent this from happening in the future to optimize performance and would like to find a lint rule to enforce that this isn't done by anyone in the future. However, I'm not seeing one.
Does anyone have any suggestions on good ways to enforce that this error isn't made other than just municating it effectively with the entire development team and helping to make sure that everyone is aware to watch for this during code reviews?
The app that I work on is having an issue with using non-memoized versions of reference types such as arrays, objects, and functions (see Object & array dependencies in the React useEffect Hook). At the moment I am going through all of our code and manually fixing the issues, however this is not an ideal long-term solution for preventing developers from making the same mistake in the future.
I am investigating ways to prevent this from happening in the future to optimize performance and would like to find a lint rule to enforce that this isn't done by anyone in the future. However, I'm not seeing one.
Does anyone have any suggestions on good ways to enforce that this error isn't made other than just municating it effectively with the entire development team and helping to make sure that everyone is aware to watch for this during code reviews?
I had the exact same thought -- It's a pervasive issue in code reviews and seeing your question was enough to motivate me to create a PR request in the eslint-plugin-react-hooks package to get this functionality added.
In the meantime (it'll probably take a while before it makes it into a release) you can use the interim eslint plugin on npm:
npm install eslint-plugin-react-hooks-unreliable-deps --save-dev
and add the following to your .eslintrc.js
:
...
extends: [
"plugin:react-hooks-unreliable-deps/remended",
...
],
...
I do hope this suits your needs, and please submit any feedback to the issues page!