Created
April 2, 2020 15:59
-
-
Save M-Bekheet/3ebf8e4c189b7bbf26d3dc65f50d11c0 to your computer and use it in GitHub Desktop.
innerHTML doesn't invoke js scripts in html, but this range method does (use it with caution)
This file contains hidden or 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
| const html = ` | |
| your html here | |
| `; | |
| class App extends React.Component { | |
| componentDidMount() { | |
| const wrapper = document.querySelector('#d3_code'); | |
| const range = document.createRange(); | |
| range.setStart(wrapper, 0); | |
| wrapper.appendChild( | |
| range.createContextualFragment(html) | |
| ); | |
| } | |
| render() { | |
| return ( | |
| <div>React Snippet</div> | |
| ) | |
| } | |
| } | |
| export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment