Skip to content

Instantly share code, notes, and snippets.

@M-Bekheet
Created April 2, 2020 15:59
Show Gist options
  • Save M-Bekheet/3ebf8e4c189b7bbf26d3dc65f50d11c0 to your computer and use it in GitHub Desktop.
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)
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