Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Saisie extends React.Component{
- constructor(props) {
- super(props);
- this.state = {
- 'todos':[]
- };
- this.addTodo = this.addTodo.bind(this);
- this.todoText = React.createRef();
- }
- addTodo(event){
- event.preventDefault();
- this.setState({'todos': [...this.state.todos, this.todoText.current.value]});
- this.todoText.current.value = "";
- }
- render(){
- const todos = this.state.todos;
- return (
- <div>
- <ul>{todos.map(todo => <li>{todo}</li>)}</ul>
- <form onSubmit={this.addTodo}>
- <input name="todo" placeHolder="aboule" type ="text" ref={this.todoText}/>
- <input type="submit" value="Add Todo"/>
- </form>
- </div>
- );
- }
- }
- ReactDOM.render(<Saisie/>,document.getElementById('root'));
Advertisement
Add Comment
Please, Sign In to add comment