For some reason I want to convert my function in react to string.
Like
toStringSpecial() {
return ( < h1 onClick = {
e => e
} > hello < /h1>)
}
render() {
return ({
this.toStringSpecial.toString()
})
}
This won't work because I used babel. What I saw is a 'spoiled' output. How to exclude babel on the fly? or inline. I don't know how to call it.
I can configure webpack to exclude babel in certain directory, but I need babel, just that I want to use the toString() method to print function.
Please check reactjs documentation link below:
https://facebook.github.io/react/docs/dom-elements.html
you should follow this structure
function createMarkup() {
return {__html: 'First · Second'};
}
function MyComponent() {
return <div dangerouslySetInnerHTML={createMarkup()} />;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.