Hey, thanks for this article. I've heard about SWR, but haven't used it yet.
But from what I see, it's a simple hook to replace useState and useEffect. Meaning, I could go with
useState
useEffect
const [data, setData] = React.useState(); React.useEffect(() => { (async() => { const data = await fetch("..."); setData(data.json()); })() }, []);
And it would have similar effect, but it would work client-side only. Or am I missing something here?
Yes, it's client-side only, it does more things internally, like revalidate when the browser tab is focused again and more feature I'm planning to write more soon.
There is a way to do SSR too, it's something I plan to write about too.
Oh, so it is more to it than it looks, nice.
I'll be waiting on a follow-up article then, thanks! :)
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hey, thanks for this article. I've heard about SWR, but haven't used it yet.
But from what I see, it's a simple hook to replace
useState
anduseEffect
. Meaning, I could go withAnd it would have similar effect, but it would work client-side only. Or am I missing something here?
Yes, it's client-side only, it does more things internally, like revalidate when the browser tab is focused again and more feature I'm planning to write more soon.
There is a way to do SSR too, it's something I plan to write about too.
Oh, so it is more to it than it looks, nice.
I'll be waiting on a follow-up article then, thanks! :)