robbestad/react-iframe

Function components cannot be given refs

Opened this issue · 1 comments

I'm using a ref with the Iframe:

<Iframe ref={this.myiframe} />

This use to work, but after updating some dependencies I'm getting the following error:

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

Check the render method of `Context.Consumer`.
    in Iframe (created by Context.Consumer)

Some of my dependencies:

    "react": "^16.8.6",
    "react-iframe": "^1.8.0",
    "styled-components": "^4.2.0",

I believe the issue is unrelated to components being functional as opposed to class based. I think the react-iframe code can be modified to allow refs to be passed by explicitly including a ref field in the props type, passing it to the base HTML iframe tag, and wrapping the component export in React.forwardRef(Iframe). As per this post: https://stackoverflow.com/questions/61192450/useref-hook-on-a-custom-component