Useeffect com limpeza
useEffect(() => {
//your code goes here
return () => {
//your cleanup code codes here
};
},[]);
Tense Trout
useEffect(() => {
//your code goes here
return () => {
//your cleanup code codes here
};
},[]);
import React, { useEffect } from 'react';
function FriendStatus(props) {
useEffect(() => {
// do someting when mount component
return function cleanup() {
// do something when unmount component
};
});
}
useEffect(() => {
// do someting when mount component
return function cleanup() {
// do something when unmount component
});
function App() {
const [shouldRender, setShouldRender] = useState(true);
useEffect(() => {
setTimeout(() => {
setShouldRender(false);
}, 5000);
}, []);
// don't render
if( !shouldRender ) return null;
// JSX, if the shouldRender is true
return <ForExample />;
}