function useMyCustomHook(ref)
{
useEffect(()=>{
if(ref.current)
{
doSomethingWithRef(ref.current);
return ()=> {cleanup(ref.current);}
}
return ()=> {doNothing();}
}, [])
}
function MyComponent()
{
const ref: React.RefObject<T> = ...;
useMyCustomHook(ref);
return <elment ref={ref} />
}
function useMyCustomHook(ref)
{
useEffect(()=>{
if(ref.current)
{
doSomethingWithRef(ref.current);
return ()=> {cleanup(ref.current);}
}
return ()=> {doNothing();}
}, [])
}
function MyComponent()
{
const ref: React.RefObject<T> = ...;
useMyCustomHook(ref);
return <elment ref={ref} />
}