ecmascript 6 - Redux/ES6 - Object literal shorthand syntax for not working in connect function as expected -
while trying dispatch action myaction
failing till rearranged es6 code syntactically appears same.
it me not getting es6 object literal shorthand, or connect
function doing under hood.
ex 1 - not working
myaction
not being interpreted correctly shorthand return of object literal key , value name match.
var mapdispatchtoprops = () => ({myaction}); mycomponent = connect( mapstatetoprops, mapdispatchtoprops )(mycomponent);
ex 2 - working
once added shorthand syntax myaction
in connect
function directly worked expected.
mycomponent = connect( mapstatetoprops, {myobject} )(mycomponent);
question:
the first case expected function return object literal identical second. why not so.
update accompany answer:
the answer below correct - if want see video explaining go here https://egghead.io/lessons/javascript-redux-using-mapdispatchtoprops-shorthand-notation
try like:
const mapdispatchtoprops = (dispatch) => (return {somecallback: () => dispatch({myaction})});
it looks first example missing dispatch
argument , call. checkout todolist example. can use somecallback
in component passed connect().
from connect()
docs:
if function passed, given dispatch. it’s return object somehow uses dispatch bind action creators in own way.
Comments
Post a Comment