Common Patterns for React? onCompleted callbacks? #3458
-
Hello All, I am having trouble finding examples of common patterns in react, outside the bare minimum, super-simple query setup. I can't anything find about best practices for using urql in conjunction with state-management tools like zustand, for example. Also, wondering what the preferred pattern for something like Apollo client's "onCompleted" hook would look like? ChatGPT4 is telling me to use an useEffect hook, but that doesn't seem great to me, too many potential side-effects with the dependency array and whatnot. Would love to see any resources out there! Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
What's your use-case behind the need for There's also the case of variables changing, do you always want that callback to be invoked, we could be showing the previous state from the hook as new data comes in? An example of the effect would be
however nothing is stopping you from abstracting this into your own What are other use-cases or patterns you are looking for? |
Beta Was this translation helpful? Give feedback.
Disclaimer: I know this got quite long, sorry! But the tl;dr here is that:
client.query
directly, inside of an effect, use an effect onuseQuery
's output (which delays further state updates, causing tearing though), or directly update your state in render (which is an “advanced” pattern and must be used with caution, so I wouldn't recommend it)