MAKING API CALLS
Without React Hooks
Something I wrote for my reference when not using react hooks.
// Making API calls
const [user, setUser] = useState();
const [error, setError] = useState();
useEffect(() => {
fetchUserData(userId)
.then(res => setUser(res.data.user))
.catch(err => setError(err.response.message));
});
// Manipulating the DOM
const [count, setCount] = useState();
Count is: ${count}
useEffect(() => {
document.title =;
});
useEffect(() => {
console.log("The component has mounted.");
}, []);
Top comments (1)
you will want to add a flag that is changed upon unmount to avoid setting the state after a component has unmounted