DEV Community

Discussion on: Difficulties Encountered with React Hooks

Collapse
vuesomedev profile image
Gábor Soós

How can I replicate the behavior of componentWillUnmount? It's important when the component subscribes to events when mounted.

Collapse
wolfhoundjesse profile image
Jesse M. Holmes • Edited on

Does returning a callback function for cleanup not work in your case?

useEffect(() => {
  // do something
  return () => yourCleanupHere()
})
Collapse
vuesomedev profile image
Gábor Soós

Missed that feature, thanks for letting me know.