Skip to main content

useUnmount

用于设定在组件卸载时执行的 hooks。

引入​

import {useUnmount} from '@baidu/acud-pro-components';

基本用法​

function App() {
const [state, {toggle}] = useToggle();

const UnmountComp = () => {
useUnmount(() => {
message.success('unmount');
});
return <p>unmountComp</p>;
};

return (
<>
<Button onClick={toggle}>切换 unmount 值</Button>
{state && <UnmountComp />}
</>
);
}

API​

type useUnmount = (fn: () => void) => void;
参数说明类型默认值
fn组件卸载时执行的函数() => void--