小编bim*_*mal的帖子

在 redux 中获取 api 的最佳方式是什么?

当我们在应用程序中使用 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
    }))
}
Run Code Online (Sandbox Code Playgroud)

这是获取api的最佳方式吗?

javascript api node.js reactjs redux

1
推荐指数
1
解决办法
1311
查看次数

标签 统计

api ×1

javascript ×1

node.js ×1

reactjs ×1

redux ×1