Reactjs 对内存进行清理
当组件失效时,如何通过Reactjs 对内存进行清理,reactjs,react-hooks,Reactjs,React Hooks,当组件失效时,如何通过cat.destroy()方法进行内存清理 const object = useMemo(() => { return new Cat() }, []) 卸载组件时执行的挂钩的清理效果。它由useffecthook上的返回函数执行: useEffect(() => { // return a function to be executed at component unmount return () => object.destroy() }
cat.destroy()
方法进行内存清理
const object = useMemo(() => {
return new Cat()
}, [])
卸载组件时执行的挂钩的清理效果。它由
useffect
hook上的返回函数执行:
useEffect(() => {
// return a function to be executed at component unmount
return () => object.destroy()
}, [object])
但它对SSR=)不起作用