No need redux if I use swr? #587
-
Hi guys, Thanks for the awesome lib. If i use redux + react. the usual flow is,
Boring job... But! No worries about multiple duplicated request, Am I right? or is there exception cases to use redux or other state managing lib? So excited to try this in next project :) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
I haven't used Redux again since I started using SWR, most of the time the only global data you put in Redux is API state, with SWR that data is on SWR cache so there is no need for Redux. However, you may still want to have global state, in that case you can rely on Redux, Context, MobX or any other solution, IMO most of the time with only using useState/useReducer + Context is enough. If you think most of the global state of your app are things like the current theme (you will use a ThemeProvider for that usually), internationalization (you will use an IntlProvider for that) and a few custom things you may need for which you could create a specific provider to each type of data and avoid setting up Redux with all the required boilerplate or adding more complementary libraries to reduce the boilerplate. |
Beta Was this translation helpful? Give feedback.
-
Just curious why "However, you may still want to have global state, in that case you can rely on Redux, Context, MobX or any other solution.". Because from the usage
no one said fetcher has to be an API, can it be a promise which just return anything. I'm just curious. Thanks. |
Beta Was this translation helpful? Give feedback.
I haven't used Redux again since I started using SWR, most of the time the only global data you put in Redux is API state, with SWR that data is on SWR cache so there is no need for Redux.
However, you may still want to have global state, in that case you can rely on Redux, Context, MobX or any other solution, IMO most of the time with only using useState/useReducer + Context is enough. If you think most of the global state of your app are things like the current theme (you will use a ThemeProvider for that usually), internationalization (you will use an IntlProvider for that) and a few custom things you may need for which you could create a specific provider to each type of data and avoi…