reactjs - React, Redux. Why my dispatch dispatches function body? -
here store creation, i'm applying redux-thunk
in applymiddleware
function
import { createstore, combinereducers, applymiddleware } 'redux' // import { composewithdevtools } 'remote-redux-devtools' import logger 'redux-logger' import thunk 'redux-thunk' import promise 'redux-promise-middleware' import tokenreducer './reducers/tokenreducer' const rootreducer = combinereducers({ tokenreducer }) const middleware = applymiddleware(logger, promise, thunk) let store = createstore(rootreducer, middleware) export default store
then connect component store , mapdispatchtoprops
function mapdispatchtoprops (dispatch) { return { gettoken: () => dispatch(fetchtokenfromstorage()) } } export default connect(mapstatetoprops, mapdispatchtoprops)(splashscreen)
here code of function fetchtokenfromstorage
export function fetchtokenfromstorage () { return (dispatch) => { dispatch(gettoken()) asyncstorage.getitem('authtoken') .then(function (token) { dispatch(gettokensuccess(token)) }) .catch(function () { dispatch(gettokenfailure()) }) } }
after execution of this.props.gettoken()
in console action looks this:
action ƒ (dispatch) {
dispatch(gettoken());
_reactnative.asyncstorage.getitem('authtoken').then(function (token) {
dispatch(gettokensuccess(token));
}).catch(function () {
dispatch(get…
it's function fetchtokenfromstorage
code. react transforms function action type name. why?
thunk must first in applymiddleware
const middleware = applymiddleware(thunk, logger, promise)
Comments
Post a Comment