当我使用多个嵌套swrconfig时,选择哪些选项?
我目前正在使用swrconfig拥有全局fetcher,但是我也想在某些组件中覆盖这个fetcher,是否会使用上层swrconfig选项?
<SWRConfig
value={{
fetcher: (resource, init) =>
fetch(resource, init).then((res) => res.json()),
}}
>
...
<SWRConfig
value={{
fetcher: customFetch
}}
>
I am currently using SWRConfig for having a global fetcher, but I also want to overwrite this fetcher in some components, would the upper level SWRConfig options be used?
<SWRConfig
value={{
fetcher: (resource, init) =>
fetch(resource, init).then((res) => res.json()),
}}
>
...
<SWRConfig
value={{
fetcher: customFetch
}}
>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将扩展嵌套
swrconfig
配置。对于您的方案,这意味着如果您调用在第二个
,它将使用在此处定义的fetcher(swrconfig
内使用custicfetch
)。另外,您还可以在
上定义fetcher
直接调用以在任何时候覆盖全局。Nested
SWRConfig
configurations will be extended. For your scenario, it means if you calluseSWR
inside the secondSWRConfig
it will use the fetcher defined there (customFetch
).Alternatively, you can also define the fetcher on the
useSWR
call directly to override the global one at any point.