useMounted()
ts
function useMounted(): () => boolean;Defined in: mounted.ts:55
React hook for checking if the component is mounted.
Returns
A Function, that returns true if the component is mounted, false otherwise.
() => boolean
Remarks
Instead of useMountedState it returns a Function that can be used to check if the component is mounted at any time, which can be useful in asynchronous operations to prevent state updates on unmounted components.
Example
tsx
function MyComponent () {
const isMounted = useMounted();
return isMounted && <p>The component is mounted.</p>;
}Since
1.0.0
Author
Simon Kovtyk