fetch方法的两个then是走完第一个再走第二个的意思么
const fetchPosts = postTitle => (dispatch, getState) => {
dispatch(requestPosts(postTitle));
return fetch(`/some/API/${postTitle}.json`)
.then(response => response.json())
.then(json => dispatch(receivePosts(postTitle, json)));
};
};
// 使用方法一
store.dispatch(fetchPosts('reactjs'));
// 使用方法二
store.dispatch(fetchPosts('reactjs')).then(() =>
console.log(store.getState())
);
response.json 是一个 Promise,就是执行完第一个异步在执行第二个。
可以参考下面的连接
https://developer.mozilla.org...