redux - React-Reduc's connect does not pass anything back to my component -


so i'm little stumped react-redux's connect, in seems not pass component. i've been trying debug morning now, , i've looked @ few tutorials can't see i've done wrong. here's snippet of relevant code below. misunderstanding connect()?

const todolist = (props) => {     console.log(props); // returns object 1 property                         // dispatch holds function.                                  // todos, filter, toggletodo & removetodo?     return (         <li> placeholder </li>      ) }  const rendertodogenerated = connect(     todostatetoprops,     tododispatchtoprops )(todolist);  const todostatetoprops = (state) => {     return {         todos: state.todos,         filter: state.filter     } }  const tododispatchtoprops = (dispatch) => {     return {         toggletodo: (toggleid) => {             dispatch(toggletodo(toggleid));         },         removetodo: (removeid) => {             dispatch(removetodo(removeid));         }     }  }    

in es6, variables declared const not exist until line they're declared on. call connect occurs before todostatetoprops , tododispatchtoprops exist, @ point they're undefined. need move call connect end of chunk of code.

also, fyi, connect supports "object shorthand" handling mapdispatch argument. instead of writing actual function have in example, can pass object full of action creators second argument, , wrapped dispatch. so, need is:

const actioncreators = {toggletodo, removetodo}; const rendertodogenerated = connect(todostatetoprops, actioncreators)(todolist); 

Comments