I have the below component , where i am displaying message for 5 sec and then removing it from home page.
when i switch between the pages, i'm getting below error sometimes. Any Advice please
index.js:1 Warning: Can't perform a React state update on an unmounted component.
This is a no-op, but it indicates a memory leak in your application.
To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.
Code:
const Home = props => {
const [visible, setVisible] = useState(true);
useEffect(() => {
setTimeout(() => setVisible(false), 5000);
}, []);
return (
<div >
{visible && <Message showDefault={false} /> }
<BaseView />
</div>
);
};
Messagecomponent tries to update itself, but the component becomes unmounted. Post the code of whatMessageis doing?