現在、amine-benselim/wp-react-redux(Github)を参考にWordPress REST API + React(Redux)の構成をためしているのですが、mapDispatchToPropsの書き方がいまひとつ理解できず苦戦しています。
例えば、actionCreators.jsのgetPosts(page)
をgetPosts(postType,page)
のようにしたい場合、Container.jsのmapDispatchToPropsはどのように書けばいいでしょうか?
お手数ですがご教示をお願いいたします。
補足:
containers/mainContainer.js
const mapDispatchToProps = dispatch => { return { getPosts: (postType, page) => { dispatch(getPosts(postType, page)).then(response => { if (!response.error) { let newPosts = posts.concat(response.payload.data); dispatch( getPostsSuccess( newPosts, +response.payload.headers["x-wp-totalpages"] ) ); } else { dispatch(getPostsFailure(response.payload.data)); } }); } }; };
export function getPosts(postType = "posts", page = 1) { const request = axios.get( `/wp-json/wp/v2/${postType}?context=embed&per_page=4&page=${page}` ); return { type: actionTypes.GET_POSTS, payload: request }; }
のように対応したところ、
`Unhandled Rejection (TypeError): Cannot read property 'message' of undefined` ./src/reducers/reducer_main.js
とのエラーが出ました。