reactjs - In Redux, what is the relationship between store.dispatch(), connect() and bindActionCreators() -


what difference between dispatch(), connect() , bindactioncreators()?

and in circumstances should use each of them?

thanks

  • dispatch - dispatches action trigger change in redux's store. logic perform change in reducer.

  • connect - react's state of particular component has nothing redux's store until apply higher order component connect() particular component. in order make redux store , react's state work together, need connect. after component has been connected redux's store, can listen changes in store. if action has been dispatched, redux store changes , because component connected store , listens changes, needs rerender. however, there small gotcha - need specify on store changes component rerender (mapstatetoprops) , state changes component allowed trigger (mapdispatchtoprops)

  • bindactioncreators - wraps action creators (a function creates action) into dispatch() call can use this: fancyactioncreator() instead of having wrap in dispatch(fancyactioncreator()).

the use case bindactioncreators when want pass action creators down component isn't aware of redux, , don't want pass dispatch or redux store it.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -