-
-
Notifications
You must be signed in to change notification settings - Fork 655
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
docs(jotai/query): same query client initialisation #1294
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 91f042b:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great addition. Thanks for working on it.
docs/integrations/query.mdx
Outdated
|
||
Although they reference methods same query keys (`'todos'`), should `useTodoMutation` be called and invalidate the query without the `Provider` initialisation step, `todosAtom` will not be prompted to refetch and will continue showing stale data. | ||
|
||
```js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's helpful to have import
statements in the code snippet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
export const useTodoMutation = () => { | ||
const queryClient = useQueryClient() | ||
|
||
return useMutation( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useMutation
is unavoidable at this point.
But, from the jotai/query
perspective (which is not tied to React),
we would like to have atomWithMutation
. (We have it in jotai/urql
.)
Would you be interested in contributing in it?? Issue 👉 #309
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, would love to attempt and contribute to it.
Will try to implement a wrapper in my existing project and make a new PR when its ready!
Thanks for the quick review, great library! 🥳
I had a project with existing integrations with
react-query
before importingjotai
to the project.Upon using
atomWithQuery
without this initialisation step, I realised that my existing functions which calledqueryClient.invalidate(...)
did not result inatomWithQuery
's query invalidating. As a result, data was not refetched and the atom had stale data.After browsing the discussions, I found the answer here #500 (reply in thread). The cause was because our functions were referencing different instances of
queryClient
Seeing that this was a discussion thread, and that others might port in jotai into existing projects which already have
react-query
integrated, I thought it might be helpful to add this piece of documentation into the official query integration documentation.Please let me know if the example and documentation is clear! Thank you.