swr
swr copied to clipboard
sometimes it automatically request again ,but the key has not changed
I have a useUser hook ,used it in father son componnet ,it can automatic request again I don't know why ,i just want it request once
<SWRConfig value={{ use: [withToken], shouldRetryOnError: false, revalidateOnFocus: false }}>
<Provider {...store}>
<RouterProvider router={router} fallbackElement={<Progress />} />
</Provider>
</SWRConfig>
function withToken(useSWRNext) {
return (key, fetcher, config) => {
const extendedFetcher = (...args) => {
return fetcher(...args)
}
const token = useUserStore.getState().userInfo.token
const schoolId = useUserStore.getState().userInfo.schoolId
if (Array.isArray(key)) {
key.push(token, schoolId)
} else if (key === null) {
} else {
throw new Error('')
}
return useSWRNext(key, extendedFetcher, config)
}
}
This example needs more clarity. Would you mind creating a demo on CodeSandbox?