How to use the react-query.queryCache.setQueryData function in react-query

To help you get started, we’ve selected a few react-query examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github exercism / website / app / javascript / components / mentoring / testimonials-list / UnrevealedTestimonial.tsx View on Github external
const updateCache = useCallback(() => {
    const oldData = queryCache.getQueryData<PaginatedResult>(cacheKey)

    if (!oldData || !revealedTestimonial) {
      return
    }

    queryCache.setQueryData(cacheKey, {
      ...oldData,
      results: oldData.results.map((oldTestimonial) => {
        return oldTestimonial.id === revealedTestimonial.id
          ? revealedTestimonial
          : oldTestimonial
      }),
    })
  }, [cacheKey, revealedTestimonial])
github exercism / website / app / javascript / components / student / IterationPage.tsx View on Github external
(response) => {
        queryCache.setQueryData(CACHE_KEY, { iterations: response.iterations })
      }
    )
github exercism / website / app / javascript / components / student / Nudge.tsx View on Github external
(response) => {
        queryCache.setQueryData(CACHE_KEY, response)
      }
    )
github exercism / website / app / javascript / components / mentoring / discussion / DiscussionPostForm.tsx View on Github external
onSuccess: (data) => {
        if (!data) {
          return
        }

        const oldData = queryCache.getQueryData<{
          posts: DiscussionPostProps[]
        }>(cacheKey) || { posts: [] }

        queryCache.setQueryData(
          [cacheKey],
          oldData.posts.map((post) => {
            return post.id === data.id ? data : post
          })
        )

        onSuccess()
      },
    }
github exercism / website / app / javascript / components / dropdowns / reputation / ReputationMenu.tsx View on Github external
onSuccess: (token) => {
        if (!token) {
          return
        }

        const oldData = queryCache.getQueryData<APIResponse>(cacheKey)

        if (!oldData) {
          return
        }

        queryCache.setQueryData(cacheKey, {
          ...oldData,
          results: oldData.results.map((oldToken) => {
            return oldToken.id === token.id ? token : oldToken
          }),
        })
      },
    }