question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exclude state setter from exhaustive-deps lint's dependencies check

See original GitHub issue

There should be a way to exclude the setter returned by useRecoilState (or the value returned by useRecoilSetState) from the lint’s dependencies check since they are known stable values:

const setValue = useRecoilSetState(...);
// or const [value, setValue] = useRecoilState(...);

React.useEffect(() => {
  setValue(...)
}, []) // should not require setValue

It should work like the values returned by React.useState and React.useReducer, which I see currently is defined in the code of the lint:

https://github.com/facebook/react/blob/61dd00db24bec6305bd72908d3617b9f2a5183da/packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js#L296-L307

I’m not sure where to file this issue actually. Should I file an issue in the react-hooks lint repo and propose a way to add exception for dependencies?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
drarmstrcommented, Jul 15, 2020

thanks @drarmstr I didn’t think of that. So is that an expected use case or should we avoid it?

It’s a supported pattern and can be common. atoms or selectors are often passed in via props or part of some dynamic config. Or, a different atom may be used from an atomFamily() or selectorFamily() based on parameter values.

1reaction
thien-docommented, Jul 16, 2020

Thanks! It should not be excluded then.

Read more comments on GitHub >

github_iconTop Results From Across the Web

reactjs - How do I configure eslint rules to ignore react-hooks ...
Just put the onChange function in your dependency array. Why is everybody's response to the tool, that React team at Facebook itself uses, ......
Read more >
Understanding the React exhaustive-deps linting warning
You will see that lint gives you a couple of options: either adding count to the dependency array or removing the dependency array ......
Read more >
Understanding the exhaustive-deps Eslint rule in React
The "react-hooks/exhaustive-deps" rule warns us when we have a missing dependency in an effect hook. To get rid of the warning, move the...
Read more >
Hooks FAQ - React
How to test components that use Hooks? What exactly do the lint rules enforce? From Classes to Hooks. How do lifecycle methods correspond...
Read more >
UseEffect Dependency Array : r/reactjs - Reddit
Either include it or remove the dependency array ... if you're a beginner) or add a eslint-disable-next-line react-hooks/exhaustive-deps .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found