React useMemo memory clean

Viewed 2759

How i can do memory cleaning by cat.destroy() method when component is dead?

const object = useMemo(() => {
  return new Cat()
}, [])
1 Answers

clean up effects for hooks you execute when a component will be unmounted. It's performed by a returned function at your useEffect hook:

useEffect(() => {
  // return a function to be executed at component unmount
  return () => object.destroy()
}, [object])
Related