Skip to content

How should I use the use-resize-observer in case of useCallback instead of useRef #45

Closed
@terpimost

Description

What if I have useCallback instead of useRef, according to https://reactjs.org/docs/hooks-faq.html#how-can-i-measure-a-dom-node

const MyComponent = () => {
    const editorContainerRef = useCallback( editorContainer =>{
        //editorContainer here is a dom node already
    },[])

   return React.createElement('div',{
        ref: editorContainerRef,
        id: 'editor-container',
    })
}

I probably can fake it by creating {current:editorContainer} and passing that to usResizeObserver like this

const { width, height } = useResizeObserver({ ref: {current:editorContainer} as React.RefObject<HTMLElement> });

but may be there is a different approach?

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions