在redux应用程序设计中,代码是否采用正确方法提供POST请求?
代码很好但是我不确定它是否也是出于任何原因的架构。
export const SITES_RECEIVED = 'SITES_RECEIVED';
//@private
function sitesReceived(sites) {
return {
type: SITES_RECEIVED,
sites: sites
};
}
//@public
export const sitesFetch = () => {
return dispatch => {
fetch('http://localhost:3000/')
.then(function(response) {
return response.text();
}).then(function(body) {
return JSON.parse(body);
}).then(function(json) {
dispatch(sitesReceived(json));
})
};
}
要求:redux,redux-thunk
答案 0 :(得分:0)
Right. No problem.
This approach is listed in official Redux documentation.
http://redux.js.org/docs/advanced/AsyncActions.html#async-action-creators