Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

missing dependency #1

Open
m3mm0 opened this issue Feb 17, 2023 · 0 comments
Open

missing dependency #1

m3mm0 opened this issue Feb 17, 2023 · 0 comments

Comments

@m3mm0
Copy link

m3mm0 commented Feb 17, 2023

Alan buenas tarde, estoy aprendiendo y mirando el tema de hook y cuando implemento algo de este estilo el linter me sale con el siguiente mensaje: React Hook useEffect has a missing dependency: 'cancelEndpoint'. Either include it or remove the dependency array.eslint react-hooks/exhaustive-deps

https://github.com/AppleLAN/CustomhooksClass/blob/434c34da6a62d67c14df82dbd740fddffdb0df49/src/hooks/useFetchAndLoad.ts#L32

para corregir el warning hice lo siguiente:

useEffect(() => {
    return () => {
      const cancelEndpoint = () => {
        setLoading(false);
        console.log("[useFetchAndLoad] cancelEndpoint");
        controller && controller.abort();
      };
    
      cancelEndpoint();
    };
  }, [controller]);

Esto es correcto o no es necesario realizar esta modificación?

en otros casos me indica que si lo tengo fuera del useEffect use un useCallback pero no esto entendiendo del todo como solucionar correctamente esto del array de dependencias.

**The 'searchEmployee' function makes the dependencies of useEffect Hook (at line 64) change on every render. Move it inside the useEffect callback. Alternatively, wrap the definition of 'searchEmployee' in its own useCallback() Hook.eslint **react-hooks/exhaustive-deps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant