-
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
chore: add a comment why fetcher accepts null #918
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit ba9c670:
|
see #738 for more details |
db5a424
to
ba9c670
Compare
@promer94 As you mentioned at #738, it's a very hacking way, so I think it should be provided as an alternative API if SWR needs the feature. |
Thanks @koba04 @promer94 ! It’s like a design debate on this specific API, there’re both pros and cons on having a default fetcher or not. And I agree that we should have an alternative way to do this. Using SWR for local data management is helpful and we are doing that too, passing null is just weird. |
I think a good way is to provide more helper hooks that are built on top of useSWR, with a good preset of configurations. import useSWRState from 'swr/state'
...
const { data, mutate } = useSWRState('key', initialVal) where useSWR(key, null, { initialData }) Just an idea, curious about what you guys think about it. |
I didn't know the use-case to use SWR for shared data management, so I'm not sure whether SWR should have the API or not. If so, exposing |
Totally agree and thanks for the great reminder here! This is always the goal of this lib, to thoughtfully support more scenarios with better UX and great performance, with a minimal API surface. Let's consider that later carefully. |
Thank you! |
UPDATED This PR adds a comment to describe why
fetchFn
acceptsnull
.This PR removes
null
from the type definition forfetchFn
, but please correct me if I'm wrong.I couldn't find any documentation about the behavior for passing null as a
fetcher
function. A case withundefined
is documented though.I also couldn't find any implementation for the case.
Is SWR supporting the case? If so, what is the expected behavior for the case?