davidjbradshaw / iframe-resizer

Keep iFrames sized to their content.

Home Page:https://iframe-resizer.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

onMessage handler not getting any data in IframeResizer in reactjs ?

avinashakula opened this issue · comments

import React, {useEffect, useRef, useState} from "react";
import IframeResizer from 'iframe-resizer-react'


export default()=>{
const ref = useRef(null);
const [message, setMessage] = useState("default");
const onMessage = (msg)=>{ 
   // Not able to receive any data
   setMessage(msg)
}

return <>
    <IframeResizer
        forwardRef={ref}
        log
        src="link"
        onMessage={onMessage}
    />
    <p>{message}</p>
</>
}

onMessage handler is not triggering when something sends back to parent from src link but its working fine with window.addEventListner "message" in useEffect,
The source link is simple webpage that return data if we click on button located in it. window.addEventLisnter ("message" is working fine in useEffect, but i want to use onMessage to get the message. Suggestions/solutions are highly appreciable.

I am facing the same issue, any update/fix/workaround for this yet?