[eslint-plugin-react-hooks] false positive with useFocusEffect
See original GitHub issueUpgraded eslint-plugin-react-hooks
to 4.0.0, it’s showing errors on React-Navigation’s useFocusEffect
hook.
import { useFocusEffect } from '@react-navigation/native';
useFocusEffect(
React.useCallback(() => {
const unsubscribe = API.subscribe(userId, user => setUser(user));
return () => unsubscribe();
}, [userId])
);
(example copied from React-Navigation
documentation)
The current behavior
Lint error:
React Hook useFocusEffect received a function whose dependencies are unknown. Pass an inline function instead.
The expected behavior
The rules shouldn’t check the function because it’s not a React useEffect
hook.
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (7 by maintainers)
Top Results From Across the Web
react-navigation-hooks: How to test useFocusEffect
Assuming you're rendering your component in your test, you need to wrap it in a fake <NavigationContext> . Doing so lets useFocusEffect look ......
Read more >SERIES: React Native (Step by Step) — Auth Flow Navigation ...
I had to bump my eslint for hooks from 4.0.0 to 4.0.3 to get rid of a false positive for useFocusEffect as the...
Read more >SERIES: React Native (Step by Step) - Auth Flow Navigation ...
I had to bump my eslint for hooks from 4.0.0 to 4.0.3 to get rid of a false positive for useFocusEffect as the...
Read more >useFocusEffect - React Navigation
To make this easier, the library exports a useFocusEffect hook: ... The useFocusEffect is analogous to React's useEffect hook. ... isActive = false;...
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
Options just cause further fragmentation. I think ideally we’d reserve Effect suffix for things that mirror the dependency API. And then e.g. react navigation could use
useOnFocus
or such.Removed in
eslint-plugin-react-hooks@4.0.3
.