reactjs - React / Redux App Issue Fetching Data from MongoDB via API -


i new redux , setting app campaign / products / users along posts mern v2.0 boilerplate.

i have setup app have fetchposts action. page has following (code bottom half)

// actions required provide data component render in sever side. postlistpage.need = [() => {    return fetchposts(); }];  // retrieve data store props function mapstatetoprops(state) {   return {     posts: getposts(state)   }; }  postlistpage.contexttypes = {   router: react.proptypes.object, };  export default connect(mapstatetoprops)(postlistpage); 

get posts passes state , should add posts object store. can hit api route , see back-end working , loading json object expected.

however, app giving me error within postreducer --

// posts export const getposts = state => state.posts.data; 

the error when go route --

typeerror: cannot read property 'data' of undefined @ getposts (/users/yasirhossain/projects/showintel/client/modules/post/postreducer.js:31:34) @ mapstatetoprops (/users/yasirhossain/projects/showintel/client/modules/post/pages/postlistpage/postlistpage.js:48:12) @ connect.configurefinalmapstate (/users/yasirhossain/projects/showintel/node_modules/react-redux/lib/components/connect.js:155:27) 

any appreciated!

in combinereducer file, forgot add postreducer alluded free_soul in comments.

export default combinereducers({   app,   posts, }); 

importing postreducer , adding it, did trick!


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -