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.

[eslint-plugin-react-hooks] false positive with useFocusEffect

See original GitHub issue

Upgraded 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:closed
  • Created 3 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
gaearoncommented, May 11, 2020

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.

2reactions
gaearoncommented, May 26, 2020

Removed in eslint-plugin-react-hooks@4.0.3.

Read more comments on GitHub >

github_iconTop 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 >

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