javascript - React child component not updating parent state -
i'm using react + electron + redux in app development. able update parent state child component in case, i'm not able it, state being updated child components.
i know reducer action being called right value, parent component being rerendered wrong 1 (the previous one), sub tree of child component being rendered right value.
my method:
i'm creating function (action handler) in parent component container:
class createexercisecanvas extends react.component { focusonsection (section) { /* function i'm refering */ store.dispatch(actions.focusonsection(section)) } render() { return ( <createexercisecanvas focusonsection={ this.focusonsection } /> ) } } const mapstatetoprops = function (store) { return { focusonsection: store.exercise.focusonsection } } export default connect(mapstatetoprops)(createexercisecanvascontainer)
and function being passed prop child container:
<index focusonsection={ this.props.focusonsection }/>
lastly, method being used onclick handler in child view. isn't right way of updating parent redux + react?
you have bind this context focusonsection function in constructor, or else doesn't know this is.
try adding constructor createexercisecanvas:
constructor(props) { super(props); this.focusonsection = this.focusonsection.bind(this); }
this annoying part using es6 classes.
Comments
Post a Comment