Skip to content

Instantly share code, notes, and snippets.

@darksh3ll
Last active November 3, 2018 09:45
Show Gist options
  • Select an option

  • Save darksh3ll/4d3df7ef1da77dc92362c68485342c22 to your computer and use it in GitHub Desktop.

Select an option

Save darksh3ll/4d3df7ef1da77dc92362c68485342c22 to your computer and use it in GitHub Desktop.
Récuperer input dans le state avec une seul function
import React, { Component } from 'react';
import './App.css';
class App extends Component {
state = {
nom:"",
email:""
};
handleSubmit = () => {
};
handleChange = (e) => {
console.log(e.target.name);
this.setState({[e.target.name]:e.target.value})
};
render() {
return (
<div className="App">
{this.state.nom}
<form onSubmit={this.handleSubmit}>
<label>
Name:
<input
type="text"
name = "nom"
onChange={this.handleChange}
/>
email:
<input
type="text"
name = "email"
onChange={this.handleChange}
/>
</label>
<input type="submit" value="Submit" />
</form>
</div>
);
}
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment