Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vijayindalkar/92751b011a641df98adc1134c9cc70d6 to your computer and use it in GitHub Desktop.
Save vijayindalkar/92751b011a641df98adc1134c9cc70d6 to your computer and use it in GitHub Desktop.
useEffect hook
### 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