当我们在应用程序中使用 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的最佳方式吗?