score:14

Accepted answer

Variables in functional components can be initialized using useRef hook (read more here). Also since you only want to run the cleanup function on unmounting and not on every re-render, you should pass an empty [] as the second argument to useEffect

const MyComponent = () => {
  const uppy = useRef(Uppy()
    .use(Transloadit, {}))

  useEffect(() => {
    return () => uppy.current.close()
  }, [])

  return <StatusBar uppy={uppy.current} />
}

score:-1

You can achieve like this.

> const MyComponent = (props) => {   let uppy;
> 
>   useEffect(() => {
>     uppy = Uppy()
>     .use(Transloadit, {});
>     return () => uppy.close()   }, [])
> 
>   return <StatusBar uppy={uppy} /> }

Related Query

More Query from same tag