useMountedState
检查组件的挂载状态
Usage
实时编辑器
function Demo() { const isMounted = useMountedState(); const [, update] = useState(0); useEffect(() => { update(1); }, []); return <div>This component is {isMounted() ? "MOUNTED" : "NOT MOUNTED"}</div>; };
结果
Loading...
API
useMountedState
Returns
() => boolean
: 组件的挂载状态