最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - React + Redux with a rest api? - Stack Overflow

programmeradmin3浏览0评论

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.

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.

Share Improve this question edited Feb 10, 2016 at 13:00 bpoiss 14k3 gold badges37 silver badges49 bronze badges asked Feb 10, 2016 at 11:15 DaveDave 1131 gold badge2 silver badges4 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 12

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.

Start with: https://egghead.io/series/getting-started-with-redux

Reffer to: What is best practice to communicate between React components and services?

Redux by design forces to build SPA application.

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.

发布评论

评论列表(0)

  1. 暂无评论