react-window-size icon indicating copy to clipboard operation
react-window-size copied to clipboard

React warning when function component is used

Open AjaxSolutions opened this issue 4 years ago • 1 comments

Apparently the line 46 results in a React warning when the comp is a function component.

ref={c => { this.wrappedInstance = c; }}

Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?

AjaxSolutions avatar Jul 31 '19 20:07 AjaxSolutions

I Temporarily suppressed this warning by Wrapping my child component in React.forwardRef like:

` const ChildComponent = React.forwardRef( (props:any, ref:any)=>{ const width = props.windowWidth; return

Child Component height {width}
} );

export default windowSize(ChildComponent); `

ahmadbsse avatar Sep 07 '20 11:09 ahmadbsse