Skip to content
Advertisement

How do you dispatch an action along with a DOM event?

I’m picking up working with react and redux, while handling state locally I am able to pass events along with onChange handlers so as to access the value with event.target.value and set them to state. Unfortunately, I am unable to pass the event to MapDispatchToProps

I have tried passing the event along with the prop assigned to the onChange handler

This is my component

JavaScript

This is my reducer

JavaScript

MapStateToProps works fine as it sets the value of the text field. The text field, however, does not record any changes.

Advertisement

Answer

In the reducer your case OnChangeText start with uppercase and dispatch({type: 'onChangeText',event}) with lowercase, so ideally to be like:

JavaScript

And in the reducer:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement