Skip to content

useUnmountedRef

Category
Export Size
135 B
Last Changed
5 days ago

A ref that reports whether the component has unmounted.

Demo

Usage

tsx
import { 
useUnmountedRef
} from '@reause/shared'
const
unmountedRef
=
useUnmountedRef
() // { current: boolean }
async function
load
() {
const
data
= await fetchData()
// `.current` is false while mounted and true once the component has unmounted if (
unmountedRef
.
current
)
return setData(
data
)
}

Type Declarations

ts
export function useUnmountedRef(): {
    current: boolean;
}

Source

Source · Demo · ahooks

Contributors

hairyf

Changelog

v0.1.7 on
55501 - feat(shared): add useUnmountedRef (#943)

Released under the MIT License. v0.1.8