DEV Community

Discussion on: How to use Resize Observer with React

Collapse
 
murashow profile image
Makar Murashov • Edited

Олексій, I suppose then this logic should live inside your component with dynamic targets. You can choose where you want to put targetRef from hook depending on something <MyElement ref={isSomething ? tagetRef : undefined}.
Other option is to slightly tweak the hook, so it will accepts the target ref as a prop, i.e. usage would be const {width, height} = useElementSize(myElementRef). But still you have to make myElementRef to be dynamic inside your component.