reactjs - Good practice to pass Action creators to functional components in a react-redux app? -
i've converted of containers functional components make them reusable , i'm wondering if it's practice pass action creators props theses functional components.
in case, i'm using tab switch between login , sign page , i'm using local state manage active class (for styling). call action creators passed down props switch between rendering login or sign page. i'm using tab in several places , i'm passing different configuration object per use cases.
homepagetabprops = { firsttabtitle:"blog", secondtabtitle:"resume", showfirsttab: this.props.showblogtab, showsecondtab: this.props.showresumetab }
is practice? yay or nay?
edit:
the active tab style giving me problems (retains value when reusing component). can have local & global state? (sorry if sounds stupid.)
passing functions props down hierarchy of components
sure accepted practice. suggest not pass bare action creators, bind them dispatch
before passing them component
. way, if child component
not connected store
not have know redux
@ (no need manually dispatch
).
as complication 2 states. there nothing wrong in mixing own component
's state part of redux
passed component
via connect
. recommend keep temporary data not important application logic inside component
's state without exposing redux
. example, of time, there no sense in sending animation timings, intermediate state of user input, etc. redux
.
but, in case looks indication of active tab direct reflection of redux
state , should fetched store. otherwise it's not clear why sending actions redux
on tab's change.
Comments
Post a Comment