Created
March 3, 2024 10:48
-
-
Save vijayindalkar/92751b011a641df98adc1134c9cc70d6 to your computer and use it in GitHub Desktop.
useEffect hook
This file contains hidden or 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
### useEffect | |
<!-- | |
function App() { | |
const [value, setValue] = useState(1); | |
return ( | |
<div> | |
<button | |
onClick={function () { | |
setValue(1); | |
console.log(1); | |
}} | |
> | |
1 | |
</button> | |
<button | |
onClick={function () { | |
setValue(2); | |
console.log(2); | |
}} | |
> | |
2 | |
</button> | |
<button | |
onClick={function () { | |
setValue(3); | |
console.log(3); | |
}} | |
> | |
3 | |
</button> | |
<button | |
onClick={function () { | |
setValue(4); | |
console.log(4); | |
}} | |
> | |
4 | |
</button> | |
<Todo id={value} /> | |
</div> | |
); | |
} | |
function Todo({ id }) { | |
const [todos, setTodos] = useState({}); | |
useEffect(() => { | |
axios | |
.get("https://sum-server.100xdevs.com/todo?id=" + id) | |
.then((response) => { | |
setTodos(response.data.todo); | |
}); | |
}, [id]); | |
// return ( | |
// <div> | |
// {todos.map((todo) => ( | |
// <Todo key={todo.id} title={todo.title} description={todo.description} /> | |
// ))} | |
// </div> | |
// ); | |
return ( | |
<div> | |
<h2>{todos.title}</h2> | |
<h5>{todos.description}</h5> | |
</div> | |
); | |
} | |
export default App; --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment