Custom hook to check if a component is mounted.
This hook returns a boolean indicating whether the component is currently mounted.
function MyComponent() { const isMounted = useMounted(); useEffect(() => { if (isMounted) { console.log('Component is mounted'); } return () => { console.log('Component will unmount'); }; }, [isMounted]); return <div>Check the console for mount status</div>;} Copy
function MyComponent() { const isMounted = useMounted(); useEffect(() => { if (isMounted) { console.log('Component is mounted'); } return () => { console.log('Component will unmount'); }; }, [isMounted]); return <div>Check the console for mount status</div>;}
Custom hook to check if a component is mounted.
This hook returns a boolean indicating whether the component is currently mounted.