React + Redux with a rest api?

2019-03-25 17:02发布

I have a simple CRUD app I am building in node, and have finished creating the rest API in Express. I am now looking to add front end functionality and wish to use react + redux as a learning exercise. It seems however all of the tutorials around this access the data directly using Redux, rather than interfacing with an internal API.

My question is, is that the correct way to build a SPA with redux? I was under the impression it was best to separate the front end from the backend so that I could, for example, build an iPhone app and not have to rebuild the backend.

Thanks in advance.

3条回答
Luminary・发光体
2楼-- · 2019-03-25 17:55

First, see examples from redux docs, "Real World" is most useful: https://github.com/reactjs/redux/tree/master/examples/real-world

Then, you can research useful utils like redux-promise-middleware.

Finally, you can try to use some complex utils for connect your redux-app with API. redux-rest-adapter is one of them.

查看更多
ゆ 、 Hurt°
4楼-- · 2019-03-25 18:01

Redux itself has nothing to do with API communication, it's the library for client-side state management. You can use whatever approach for firing and handling requests, most common are using custom api-connecting middleware, returning functions, which fire requests, from action-creators and using them with thunk-middleware or using alternative approaches like rx-bridges or sagas.

查看更多
登录 后发表回答