Skip to content
This repository has been archived by the owner on Nov 11, 2023. It is now read-only.

Mutation function inside a useEffect #327

Closed
omegafranco opened this issue Jan 7, 2021 · 2 comments
Closed

Mutation function inside a useEffect #327

omegafranco opened this issue Jan 7, 2021 · 2 comments

Comments

@omegafranco
Copy link

omegafranco commented Jan 7, 2021

I'm trying to use a mutate function inside a useEffect. Since I have the exhaustive-deps lint rule, i need to add this function to the depency list in my effect. But the mutate function reference is changing every render and is triggering my effect.

To work around this I had to memoize the mutation in a useCallback and used that as a depedency instead. Is this the expected path to take? It seems like a lot of overhead. Given the same args, shouldn't we receive the same reference from useMutate in every render?

@omegafranco omegafranco changed the title useMutate inside a useEffect Mutation function inside a useEffect Jan 7, 2021
@fabien0102
Copy link
Contributor

Hello, thanks for the reporting, this is probably the same kind of mess than this issue #186

Sadly I don't have any quick win / time for this right know, but I totally agree that this can be an issue! So yeah, for now, eslint ignore or useCallback is the way to go. Sorry for the overhead 😕

@amacleay-cohere
Copy link
Contributor

This likely can close given #186 should be resolved

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

No branches or pull requests

3 participants