mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-31 19:01:54 +02:00
iframe example - use an onLoad callback instead of the ref (#4758)
* use an onLoad callback instead of the ref * expect body to not be null on the iframe test * remove onLoad prop
This commit is contained in:
@@ -105,14 +105,13 @@ const MarkButton = ({ format, icon }) => {
|
||||
}
|
||||
|
||||
const IFrame = ({ children, ...props }) => {
|
||||
const [contentRef, setContentRef] = useState(null)
|
||||
const mountNode =
|
||||
contentRef &&
|
||||
contentRef.contentWindow &&
|
||||
contentRef.contentWindow.document.body
|
||||
const [iframeBody, setIframeBody] = useState(null)
|
||||
const handleLoad = e => {
|
||||
setIframeBody(e.target.contentDocument.body)
|
||||
}
|
||||
return (
|
||||
<iframe {...props} ref={setContentRef}>
|
||||
{mountNode && createPortal(React.Children.only(children), mountNode)}
|
||||
<iframe srcDoc={`<!DOCTYPE html>`} {...props} onLoad={handleLoad}>
|
||||
{iframeBody && createPortal(children, iframeBody)}
|
||||
</iframe>
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user