I use the connect function provided by react-redux . I would redo your code to look something like this (ES6 syntax):
container.js
import {connect} from 'react-redux' import {presenter} from './presenter' import {actions} from '../../loader' const mapStateToProps = (state, props) =>({ creativeName: props.creativeName }) const mapDispatchToProps = (dispatch) =>({ updateDraft : (creativeName) => dispatch(actions.updateDraft('creativeName', creativeName)) }) const container = connect(mapStateToProps, mapDispatchToProps)(presenter) export { container }
actions above are just a file containing the standard Action Action creators.
presenter.js
function presenter ({creativeName}, updateDraft) { const onBlur=e=>updateDraft(e.target.value) return ( <Row> <Col lg={12} className="row-margin"> <ControlLabel>*Name</ControlLabel> <div className="campaign-name"> <FormControl value={creativeName} type="text" onBlur={e=>onBlur(e)} className="campaign-name-text-field" /> </div> </Col> </Row> ) } export { presenter }
In truth, I would not use any local state at all and instead use a selector (see reselect ) to pull the local state of components from the global state, a bit like this:
presenter.js - mapStateToProps
import {actions, services} from '../../loader' const mapStateToProps = (state) =>({ state: services.CreativeName.selector.getAll(state) })
Of course, this is a great way to do things, I prefer it, but I'm not sure if this is easier.
source share