News for hackers. Stuff that matters.
Re:React Implementation Notes by cel1ne on Thursday October 13, 2016 @04:34AM (#12699313)
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.

There are no comments on this comment yet.