Closed kevmodrome closed 3 years ago
Hello Kevin, thanks a lot for the feedback.
a PR with this change is relatively easy. I would accept it as long as it updates the docs too.
The use convention is because I also use the same underlying package I built for the vue version of it, that uses the use convention as well. I do understand your concerns and I'm more than welcome to accept such change.
At the end of the day, this change is just for the default SWR instance that we ship with. However, I do think most people will end up creating their own instance, thus allowing them to name it however they want:
import { createSWR } from 'sswr'
const swr = createSWR({
// Configure a global fetcher for all SWR hooks. This
// can be replaced with anything that returns a promise
// with the data inside, for example: axios.
fetcher: (key) => fetch(key).then((res) => res.json()),
})
// Default instance exports.
export const useSWR = swr.useSWR
export const mutate = swr.mutate
export const revalidate = swr.revalidate
export const clear = swr.clear
You can just change the exports to whatever name suits best for your use case :)
For the default exports feel free to commit a PR!
Hi @ConsoleTVs. If you're not working on it, I'm willing to submit a PR for this issue. As Kevin mentioned, just swr
would be awesome. Hope that's okay?
Whoops! Didn't see the comment reactions or else would've done this long ago :P. Thanks @frederikhors :)
I am not really in the track for this anymore, however it is relatively easy to make a custom instance (as in acios) and just re-export the methods with the name you want!
Love the idea of swr in Svelte but it would be neat to keep it aligned with how and what things are called in Svelte.
I assume the
use
moniker is taken from the react ecosystem (hooks)? The use keyword has a meaning in Svelte and it will probably confuse users a bit. I suggest renaminguseSWR
to something else. Maybe just...swr()
?