Last active
April 4, 2021 17:19
-
-
Save myogeshchavan97/aff9cc01da65d648c2e3cee0655222c1 to your computer and use it in GitHub Desktop.
Child Component useEffect Demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState } from "react"; | |
import ReactDOM from "react-dom"; | |
import TodoForm from "./TodoForm"; | |
import TodoList from "./TodoList"; | |
const App = () => { | |
const [todos, setTodos] = useState([]); | |
const handleFormSubmit = event => { | |
event.preventDefault(); | |
setTodos([...todos, event.target.elements.todo.value]); | |
event.target.elements.todo.value = ""; | |
}; | |
return ( | |
<div> | |
<TodoForm handleFormSubmit={handleFormSubmit} /> | |
<TodoList todos={todos} /> | |
</div> | |
); | |
}; | |
ReactDOM.render(<App />, document.getElementById("root")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment