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.

When mutate after an action, to want to get the request list, use queryCache. RefetchQueries or queryCache. InvalidateQueries list update, but did not make the list updates.Neither approach works

See original GitHub issue

` export const useTouchListComplate = () => {

const [mutate] = useMutation((options: any) => { return fetch(${DOMAIN.BIBLE_INSPIRE}${PATH.WORKBENCH.API_LIST_COMPLATE}, { method: ‘POST’, body: objToParam({ deptcode: options.deptcode, list_code: options.list_code }) }) }, { onSuccess: (data: any, param: any) => { console.log(data) queryCache.refetchQueries(${DOMAIN.BIBLE_INSPIRE}${PATH.WORKBENCH.API_TABLE_EACH_DATA}/${param.tabId}, { active: true }) } }) return [ mutate ] } `

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

5reactions
TkDodocommented, Sep 23, 2020

Not sure I got the question right, but here are some approaches to what I think you want to achieve that have been working well for me:

  1. After mutation, just invalidate the query cache for your key. The next time a component renders that needs that data, it will be re-fetched.

You can see this working in this example: https://react-query.tanstack.com/docs/examples/optimistic-updates

especially this part:

// After success or failure, refetch the todos query
onSettled: () => {
    cache.invalidateQueries('todos')
},
  1. alternatively, if your mutation returns the result, you can just put it in the query cache. I will stick with the todos example:
useMutation(
    text => axios.post('/api/data', { text }),
    {
      onSuccess: (allTodos) => {
        cache.setQueryData('todos', allTodos)
      },
    }

this approach will manually update the cache with the data from the server, so it will not re-fetch it. This is useful if, like in my example, your server already returns the new data as a result of the mutation request.

2reactions
TkDodocommented, Sep 23, 2020

Since you have suspense set to true, maybe this is a duplicate of https://github.com/tannerlinsley/react-query/issues/1065 ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

When mutate after an action, to want to get the request list, use ...
RefetchQueries or queryCache. InvalidateQueries list update, but did not make the list updates.Neither approach works #1081.
Read more >
React-Query and Query Invalidation Question - Stack Overflow
The mutation does not automatically triggers a refetch. The way to achieve this using react-query is via queryCache.invalidateQueries to ...
Read more >
Refetching queries in Apollo Client - Apollo GraphQL Docs
The InMemoryCache helps you determine which active queries might have been invalidated by recent cache updates. Local cache updates and refetching work ......
Read more >
Query Invalidation | TanStack Query Docs
For that purpose, the QueryClient has an invalidateQueries method that lets you intelligently mark queries as stale and potentially refetch them too! `tsx....
Read more >
React Query Tutorial - 22 - Query Invalidation - YouTube
Your browser can 't play this video. Learn more.
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