DEV Community

Discussion on: Introduction to SWR

Collapse
 
tomekbuszewski profile image
Tomek Buszewski

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

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?

Collapse
 
sergiodxa profile image
Sergio Daniel Xalambrí

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.

Collapse
 
tomekbuszewski profile image
Tomek Buszewski

Oh, so it is more to it than it looks, nice.

I'll be waiting on a follow-up article then, thanks! :)