@jerad
To append a React.js component into an iframe, you can follow these steps:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
import React from 'react'; import ReactDOM from 'react-dom'; const MyComponent = () => { return <h1>Hello World!</h1>; }; const MyComponentInIframe = () => { const iframe = document.getElementById('my-iframe'); const iframeDocument = iframe.contentDocument; ReactDOM.render(<MyComponent />, iframeDocument.body); return ( <iframe id="my-iframe" width="400" height="200"></iframe> ); }; |
In this example, we have created a simple functional component MyComponent and then rendered it inside the iframe element with id 'my-iframe' using the ReactDOM.render() method.
Make sure to adjust the size and styling of the iframe to fit your requirements.