Skip to content
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

sometimes it automatically request again ,but the key has not changed #3000

Open
vaynevayne opened this issue Aug 8, 2024 · 0 comments
Open

Comments

@vaynevayne
Copy link

vaynevayne commented Aug 8, 2024

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)
  }
}
@vaynevayne vaynevayne changed the title I will request again from time to time, but the key has not changed sometimes it automatically request again ,but the key has not changed Aug 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant