Skip to content

Instantly share code, notes, and snippets.

@koba04
Created August 18, 2020 00:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koba04/09a2d9c0563a2b8ecd6a10cb106cf369 to your computer and use it in GitHub Desktop.
Save koba04/09a2d9c0563a2b8ecd6a10cb106cf369 to your computer and use it in GitHub Desktop.
const Foo = () => {
const someRef = React.useRef<{ someSetupMethod: () => void; someCleanupMethod: () => void }>(null)
React.useEffect(() => {
if (someRef.current === null) return
someRef.current.someSetupMethod()
return () => {
if (someRef.current === null) return
// react-hooks/exhaustive-deps warns this
someRef.current.someCleanupMethod()
}
})
return <div>foo</div>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment