我有几种类似的RSAA动作:
export const getUserById = id => ({
[RSAA]: {
endpoint: "...",
method: "GET",
headers: { "Content-Type": "application/json" },
credentials: "include",
types: [
GET_USER_BY_ID_REQUEST,
GET_USER_BY_ID_SUCCESS,
GET_USER_BY_ID_FAILURE
]
}
});
export const getUserPosts = id => ({
[RSAA]: {
endpoint: "...",
method: "GET",
headers: { "Content-Type": "application/json" },
credentials: "include",
types: [
GET_USER_POSTS_REQUEST,
GET_USER_POSTS_SUCCESS,
GET_USER_POSTS_FAILURE
]
}
});
要使用thunk(我认为)来链接这两个动作,我该怎么办?
我可以创建名为getUserThenPosts
的第三个动作吗?但是那会是什么样?
答案 0 :(得分:0)
使用redux-thunk
并创建名为getUserThenPosts
的第三个动作。
export const getUserThenPosts = id => dispatch => {
return dispatch(getUserById(id))
.then((payload) => {
return dispatch(getUserPosts(payload.someIdFromUserPayload)));
};
};
我假设getUserPosts
需要来自user
有效负载的参数。