Answer the question
In order to leave comments, you need to log in
How to make a request to the server in React?
There is a form where data is entered (first name, last name, etc.). How to send this data to the server in React?
class App extends React.Component {
constructor() {
super();
this.state = {value: ''};
}
handleChange(event) {
this.setState({value: event.target.value});
}
handleSubmit(event) {
alert(this.state.value);
event.preventDefault();
}
render() {
return <form onSubmit={this.handleSubmit.bind(this)}>
<label>
Name:
<input value={this.state.value} onChange={this.handleChange.bind(this)} />
</label>
<input type="submit" />
</form>
}
}
Answer the question
In order to leave comments, you need to log in
you can put a post with your data on the server into the handleSubmit function using fetch or axios
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question