loading...

re: Introduction to SWR VIEW POST

FULL DISCUSSION
 

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?

 

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! :)

code of conduct - report abuse