Skip to content Skip to sidebar Skip to footer

Is There A Good Way To Preventdefault When Dispatching An Action In React/redux?

I'm dispatching an action that runs a reducer that pushes some text to my redux state on form submit. I know in Vue you can preventDefault right in the DOM but I haven't seen anyth

Solution 1:

What i would do is define a function in your component called _onSubmit and have it do like so:

_onSubmit(e) {
  e.preventDefault();
  this.props.data.addLink(this.state.text)
}

and then your form component just uses this._onSubmit for its onSubmit handler

<form className="form form-inline" onSubmit={this._onSubmit} style={styles.form}>

this will handle the event and dispatch the correct action.

Post a Comment for "Is There A Good Way To Preventdefault When Dispatching An Action In React/redux?"