swr icon indicating copy to clipboard operation
swr copied to clipboard

SWRConfig fetcher prop doesn't exist/work

Open d4lek opened this issue 6 years ago • 3 comments

Hi, I'm trying to configure SWRConfig to use "global" fetch function in all hooks but it doesn't seem to work. Also config interface doesn't have a value called fetcher, like it's shown in the docs

codesandbox

d4lek avatar Feb 28 '20 11:02 d4lek

@davidalekna I don't know about why the config interface doesn't have a value called fetcher, but in your example on codesandbox you are using SWRConfig wrong, since SWRConfig is a Context.Provider, the prop that you should pass should be value not values

<SWRConfig
  value={{
    fetcher: apiFetcher
  }}
>
  <SomeComponent />
</SWRConfig>

cristianbgp avatar Feb 28 '20 15:02 cristianbgp

@davidalekna @cristianbgp https://github.com/zeit/swr/blob/master/src/types.ts#L18 there is the fetcher in the config interface, https://github.com/zeit/swr/blob/master/src/config.ts#L55 that is the default config

sergiodxa avatar Feb 28 '20 16:02 sergiodxa

@cristianbgp damn how did I miss that values vs value 😅

thanks for clarification guys!

d4lek avatar Feb 28 '20 18:02 d4lek