【发布时间】:2019-02-22 01:35:02
【问题描述】:
当我们在应用程序中使用 redux 时,如何编写在 react 应用程序中获取 api 资源的最佳方法。
我的动作文件是 actions.js
export const getData = (endpoint) => (dispatch, getState) => {
return fetch('http://localhost:8000/api/getdata').then(
response => response.json()).then(
json =>
dispatch({
type: actionType.SAVE_ORDER,
endpoint,
response:json
}))
}
这是获取 api 的最佳方式吗?
【问题讨论】:
-
这看起来不错
-
使用中间件更清洁 IMO
标签: javascript node.js reactjs api redux