GithubHelp home page GithubHelp logo

Comments (8)

robbestad avatar robbestad commented on July 20, 2024 3

from react-iframe.

robbestad avatar robbestad commented on July 20, 2024 1

All right, will look at this next!

from react-iframe.

jcvalerio avatar jcvalerio commented on July 20, 2024

@svenanders I was abe to implement this use case (@conorot) in previous versions
v1.5.0 to v1.6.2

But this is not supported anymore because since v1.7.0. I guest you migrate the implementation from
PureComponent to Stateless or Function Component

Since then this warning is fire by React
Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()

And I'm not able to get a reference.

This works on v1.6.2 but not in 1.7.0

import React from 'react'
import { Button } from 'antd'

export default class DemoComponent extends React.PureComponent {
  formRef = {
    iFrame: null,
  }

  handleSubmit = () => {
    const { iFrame } = this.formRef
    if (iFrame && iFrame.refs) {
      const ref = iFrame.refs.iframe
      ref.contentWindow.postMessage('submit form', '*')
    }
  }

  saveIFrameRef = formRef => {
    this.formRef.iFrame = formRef
  }

  render() {
    return (
      <div>
        <Iframe
          url="SOME_URL"
          width="100%"
          height="600px"
          id="legacyEditor"
          display="initial"
          position="relative"
          allowFullScreen
          ref={this.saveIFrameRef}
        />
        <Button key="submit" type="primary" onClick={this.handleSubmit}>
          {'Send message to the IFrame'}
        </Button>
      </div>
    )
  }
}

from react-iframe.

adtsoft avatar adtsoft commented on July 20, 2024

I have code that is very similar to what @jcvalerio is doing. I had to roll back to 1.6.2.

from react-iframe.

hlolli avatar hlolli commented on July 20, 2024

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

from react-iframe.

adtsoft avatar adtsoft commented on July 20, 2024

@hlolli that is the problem we are discussing. If you use version 1.6.2 the above example from @jcvalerio will work.

from react-iframe.

marcantoinepelletier avatar marcantoinepelletier commented on July 20, 2024

Any chance to see this feature added directly into the package ? :)

from react-iframe.

veerjainATgmail avatar veerjainATgmail commented on July 20, 2024

Does this work now? Any suggestions on alternatives? thanks.

from react-iframe.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.