Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const updateCache = useCallback(() => {
const oldData = queryCache.getQueryData(cacheKey)
if (!oldData || !revealedTestimonial) {
return
}
queryCache.setQueryData(cacheKey, {
...oldData,
results: oldData.results.map((oldTestimonial) => {
return oldTestimonial.id === revealedTestimonial.id
? revealedTestimonial
: oldTestimonial
}),
})
}, [cacheKey, revealedTestimonial])
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()
},
}
onSuccess: (token) => {
if (!token) {
return
}
const oldData = queryCache.getQueryData(cacheKey)
if (!oldData) {
return
}
queryCache.setQueryData(cacheKey, {
...oldData,
results: oldData.results.map((oldToken) => {
return oldToken.id === token.id ? token : oldToken
}),
})
},
}