3 ms·
I dislike redux-thunk, because it breaks serialisability. I don't know redux-saga, but this is my way of doing it: Create a data-structure like "running reques
by cel1ne 10y ago
I dislike redux-thunk, because it breaks serialisability. I don't know redux-saga, but this is my way of doing it:
Create a data-structure like "running requests" in your state and put a serializable object in, could be complex or just a string "GET_USER_DATA".
Then write a simple "NetworkManager". React reconciles the UI to match the state, the NetworkManager does the same for your "running requests": make the actual running requests match those in the state.
In some projects I even (ab)used React to do that: add a component that renders a <div/> and manage the XHR in componentDidUpdate etc.
<Network>
<Get url="http://..."/ onLoad={() => state.GETsuccess(...)}>
</Network>
This way everything can be paused and is easy to reason about. You get cancellation and reuse of requests for free by using keys.