html-react-parser replace onClick
html-react-parser replace example with onClick
https://github.com/remarkablemark/html-react-parser/issues/53
by remarkablemark
HTML
<div id="root"></div>
<!-- HTMLReactParser -->
<script src="https://unpkg.com/html-react-parser@latest/dist/html-react-parser.min.js"></script>
React
class App extends React.Component {
work() {
alert('work');
}
render() {
return HTMLReactParser('<button id="placeholder"></button>', {
replace: ({ attribs }) => {
if (attribs && attribs.id === 'placeholder') {
return <button onClick={this.work}>Click Me</button>;
}
}
});
}
}
ReactDOM.render(<App />, document.getElementById('root'));