titouancreach / vuejs-redux

Flexible binding between Vue and Redux
57 stars 11 forks source link

mapDispatchToProps is not updated inside the provider #12

Closed titouancreach closed 6 years ago

titouancreach commented 6 years ago

when you use this pattern:

const mapDispatchToProps = myProp => dispatch => ({
  myFunction: .....
})

export default {
  props: ['myProp'],

  render() {
    return (
      <Provider store={store} mapDispatchToProps={mapDispatchToProps(this.myProp)}>
        {({myFunction}) => (
          <Child myFunction={myFunction} />
        )}
     </Provider>
  }
}

Provider store the function mapDispatchToProps(this.myProp) in its state. Since there is no watcher, even if the provider update myProp, mapDispatchToProps is never recalculated inside the Provider.

We don't even need to store mapDispatchToProps. We can direclty call the prop mapDispatchToProps. In this way, if the prop change in the provider, the Provider will be updated with the good function.