-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Victor Kotseruba
committed
Mar 14, 2019
1 parent
965aeb4
commit 9484237
Showing
6 changed files
with
49 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,34 @@ | ||
import React from 'react'; | ||
|
||
const Preview = ({html, iframeKey})=> ( | ||
<div className={styles.root}> | ||
<div className={styles.iphone5}> | ||
<iframe seamless | ||
key={iframeKey} | ||
src={`data:text/html;charset=utf-8,${html}`} | ||
className={styles.frame}/> | ||
</div> | ||
</div> | ||
); | ||
|
||
export default Preview; | ||
export default class Preview extends React.PureComponent { | ||
|
||
componentDidMount() { | ||
this.setIframeContent(); | ||
} | ||
|
||
componentDidUpdate(prevProps) { | ||
if (prevProps.html !== this.props.html) { | ||
this.setIframeContent(); | ||
} | ||
} | ||
|
||
render() { | ||
return ( | ||
<div className={styles.root}> | ||
<div className={styles.iphone5}> | ||
<iframe | ||
src="about:blank" | ||
ref="iframe" | ||
className={styles.frame} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
setIframeContent() { | ||
this.refs.iframe.contentDocument.write(this.props.html); | ||
this.refs.iframe.contentDocument.close(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters