React + Redux 与 rest api? [英] React + Redux with a rest api?

查看:26
本文介绍了React + Redux 与 rest api?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 node 中构建了一个简单的 CRUD 应用程序,并在 Express 中完成了其余 API 的创建.我现在正在寻找添加前端功能并希望使用 react + redux 作为学习练习.然而,似乎所有与此相关的教程都直接使用 Redux 访问数据,而不是与内部 API 接口.

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.

我的问题是,这是使用 redux 构建 SPA 的正确方法吗?我的印象是最好将前端与后端分开,这样我就可以,例如,构建一个 iPhone 应用程序,而不必重新构建后端.

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.

提前致谢.

推荐答案

Redux 本身与 API 通信无关,它是客户端状态管理的库.您可以使用任何方法来触发和处理请求,最常见的是使用自定义 api 连接中间件,返回函数,触发请求,来自动作创建者并将它们与 thunk-middleware 一起使用或使用替代方法像 rx-bridgessagas.

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.

这篇关于React + Redux 与 rest api?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆