Hacker News new | past | comments | ask | show | jobs | submit login

> jumping through 7 files just to find the API request that gets shipped is slightly insane.

The API request is in the file that represents the point at which the API request is made by the user (previously in a loader component or, now, using a hook, in future using suspense), so I would say it involves jumping through 0 files, as opposed to several if I move it to redux (the dispatch occurs at the UI trigger point, then I have to drill through several other layers of abstraction). In practice there's normally some facade in front of the API to prefill values and also to make it easier to mock for testing, but if anything that just makes it simpler as the facade acts as a reference.

> how about displaying a default failure screen?

   failure && <FailureComponent>{failure.message}</FailureComponent>
This is I guess down to a preferred philosophical approach but from my pov React is a UI library and it's _really_ good at showing conditional UI. Redux is a state container and is not great for this. I don't feel I want that in Redux, I want Redux purely to be a reference the state of the data in the app; loading/req/etc states are not that. Whenever I've moved error/request/loading/failure state to Redux (ie almost every app I've made over the past four years before this year) it involves a series of abstractions to track the current request. Whereas React can do this out of the box at the point the action is taken: make the request, show some state, if the request succeeds, dispatch the data to the store and [re]render the component that displays the data based on the state of the store.

> but how do you put the result back in the store?

    dispatch({ type: "foo", data: "bar"})
And have a component that renders based on props in the store, same as normal.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: