I
I
IIITRIX2020-05-21 15:26:53
React
IIITRIX, 2020-05-21 15:26:53

How to change state on form submission?

Good day, friends!
Help me to understand.
Now when you click on the Publish button, everything is sent fine
. I need that when you click on save, the state changes to status 'D'
My state

state = {
    data: {
      status: 'P'
    }
  }

There is a form.
<form onSubmit={this.onSubmit}>
    <input type='submit'>Опубликовать</span>
    <span>Сохранить</span>
</form>

Handler
onSubmit = e => {
    this.props.submit(this.state.data)
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hzzzzl, 2020-05-21
@IIITRIX

span onClick={() => this.setState({ data: { status: 'D' } })}
better put it in a separate function for readability

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question