Replies: 1 comment
-
I call the approach data-aware components, I always use it so my components can move and they will already have the data they need to work, thanks to request deduping of SWR you can even use N times the same key and it will only fetch it once so there is not issue in duplicating that. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am currently thinking about to smart up my components by no longer having them being "dumb" but each of them handling its own live server state.
Take my favourite and watchlist icons. Before they were dumb components that rendered a icon depending on handed in props. Now I have converted them to be connected to a swr hook and toggle their server state themselves.
before:
after:
The problem with the old approach was that I had to connect the component whenever I wanted to render it.
With the new approach I can just render it everywhere and all those components will stay in sync (since they use the same cache-key in
useFavourite
.Is this a recommended approach of using swr?
Beta Was this translation helpful? Give feedback.
All reactions