iframe-resizer-react icon indicating copy to clipboard operation
iframe-resizer-react copied to clipboard

add method to imperative handle that exports iframe html element

Open monsterkrampe opened this issue 4 years ago • 3 comments

closes #42

I think it is important to have the option to access the iframe element directly because this adds a lot more flexibility to the component. This is just a simple way of accessing the iframe element from the outside without changing too much code and also without changing the signature of the component so this is currently fully backwards compatible. There may be better ways to achieve this and I'm happy to discuss the changes.

Some further ideas:

One could use React.forwardRef but then the prop would be called ref instead of forwardRef. Still this may be more ideomatic.

If the iframe element is already accessible from outside the component, there is no real need anymore to proxy resize, moveToAnchor and sendMessage. Therefore, one could even think about omitting useImperativeHandle alltogether and just setting the forwardRef on the iframe element directly. Still this also would not be backwards compatible.

Let me know what you think :)

monsterkrampe avatar Feb 08 '21 12:02 monsterkrampe

@davidjbradshaw can you give some feedback regarding this PR?
I would like to know what you think about the issue and the possible solutions :)

monsterkrampe avatar Apr 07 '21 07:04 monsterkrampe

We need to pass a custom message that a third-party team developed, they are waiting for a specific message inside the iframe and using iframeRef.sendMessage the message is tranformed into a string with a [iFrameSizer]message: prefix.

This is urgent, we need this feature.

We expect to send:

{
  "data": {
    "code": 2,
    "message": "User pool 13",
    "action": "validate"
  }
}

But the message goes as bellow:

[iFrameSizer]message:{\"data\":{\"code\":2,\"message\":\"User pool 13\",\"action\":\"validate\"}}

devgnx avatar Jun 30 '21 19:06 devgnx

@kayyali18 apparently published a new npm package including this fix. See https://www.npmjs.com/package/iframe-resizer-react-custom and https://github.com/kayyali18/iframe-resizer-react/pull/1.

I guess this is a viable workaround.

Disclaimer: I have nothing to do with this fork :D

monsterkrampe avatar Jun 30 '22 15:06 monsterkrampe