I have the following code to try and work out whether a component instance is an instance of a class component and has a ref
property:
type Refable<T> = React.ReactElement<T> & { ref: React.RefObject<T>; }; const componentHasRef = function<T>(component: React.ReactElement<T> | Refable<T>): component is Refable<T> { return !!(component as any).ref; };
Is there a better way than return !!(component as any).ref;
of doing this?
0 comments:
Post a Comment