React Hook useEffect has a missing dependency
See original GitHub issueimport { useState } from "@hookstate/core";
import { useEffect } from "react";
export default function App() {
const state = useState("whatever");
useEffect(() => {
state.set("foobar");
}, []);
return (<></>);
}
Linter warning:
React Hook useEffect has a missing dependency: 'state'. Either include it or remove the dependency array. (react-hooks/exhaustive-deps)
The reason I’m updating the state in the effect is because I’m fetching data and updating the state when it comes back. I just didn’t include that in the code above.
I don’t want to pass in state into the array because I don’t want it to re-render every time the state changes. Is there a way to do this without disabling the linting rule?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6 (5 by maintainers)
Top Results From Across the Web
How to fix missing dependency warning when using useEffect ...
Resolution: Step 1: Move business logic it to separate const. Now the warning is: React Hook React.useEffect has a missing dependency: 'roleChecking'. const ......
Read more >React Hook useEffect has a missing dependency error
The warning "React Hook useEffect has a missing dependency" occurs when the useEffect hook makes use of a variable or function that we...
Read more >How To Fix "react hook useeffect has a missing dependency"?
Add the missing dependency; Move the dependency inside the useEffect hook; Disable the ESLint rule. This article will explore all of those ...
Read more >How to fix - react hook useEffect has missing dependencies?
One of the least recommended solutions to fix “React Hook useEffect has a missing dependency” is to remove the dependencies and avoid the ......
Read more >Solve - React Hook useEffect has a missing dependency error.
The warning “React Hook useEffect has a missing dependency” occurs when the useEffect hook makes use of a variable or function outside its...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

It is React thing. You can ask the same question about any other variable, not necessary state variable. As far as I know you can disable a specific lint rule per line. You can also try the following:
“Is there a way to do this without disabling the linting rule?” as @TroyJoachim suggested, set the state when it is fetched. You can also check if hookstate’s built in support for async state would help in your case.