-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
UseSWR wrapper doesnt override and routes to the wrong fetcher (SWR global config's) #2155
Comments
@ridhwaans import useSWR from 'swr'
export const useSharedState = (key, initial) => {
const { data: state, mutate: setState } = useSWR(key, null, {
fallbackData: initial,
fetcher: null
})
return [state, setState]
} It might be better to provide a better way for this if we'd like to push out this pattern. |
I have the exact same issue as OP. I was trying to find workarounds myself, such as providing a noop operation |
Bug report
Description / Observed Behavior
As the title says, I have a useSharedState hook that is used to pass state between components without prop drilling. This hook is not for http resources, it doesnt have a url fetcher but has an initial state option
I also have SWR global config in my App.js with its own fetcher
When I make an
useSWR
call it adds the base url to query endpoints in componentsHowever when I have
useSWR
anduseSharedState
in the same component or when I calluseSharedState
directly, it goes to the wrong fetcher & url endpoint defined thats in SWRConfigit returns
Expected Behavior
Need all SWR calls with resource urls i.e.
useSWR('/books')
to follow the global fetcher in<SWRConfig/>
but other SWR wrappers likeuseSharedState()
that is not meant for API calls should not use global fetcher optionWhat am I doing wrong, do I need to fix the hook param to override fetcher?
Repro Steps / Code Example
Additional Context
swr version
"^1.3.0",
The text was updated successfully, but these errors were encountered: