Skip to content

Commit

Permalink
iframe example - use an onLoad callback instead of the ref (ianstormt…
Browse files Browse the repository at this point in the history
…aylor#4758)

* use an onLoad callback instead of the ref

* expect body to not be null on the iframe test

* remove onLoad prop
  • Loading branch information
adrid authored Jan 10, 2022
1 parent 8daa77e commit e3a325f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
1 change: 1 addition & 0 deletions cypress/integration/examples/iframe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const getIframeBody = () => {
.its('body')
// automatically retries until body is loaded
.should('not.be.undefined')
.should('not.be.null')
.then(cy.wrap)
)
}
Expand Down
13 changes: 6 additions & 7 deletions site/examples/iframe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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>
)
}
Expand Down

0 comments on commit e3a325f

Please sign in to comment.