useMountedEffect()
ts
function useMountedEffect(effect): void;Defined in: mounted.ts:88
React hook for calling the effect only when the component is mounted.
Parameters
| Parameter | Type | Description |
|---|---|---|
effect | EffectCallback | Effect callback to be executed when the component is mounted. |
Returns
void
Example
tsx
function MyComponent () {
useMountedEffect(() => {
console.log("This will only be logged when the component is mounted, and will not be logged if the component is unmounted or rerendered.");
})
}Since
1.0.0
Author
Simon Kovtyk