-
Notifications
You must be signed in to change notification settings - Fork 48.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
can't use variable containing html to set inner contents of tag. #5743
Comments
based on this page. |
Solved it! It required a function call to return a JSON object to that the attribute could be set properly. However I still maintain that it should work be able to take a JSON object directly from the attribute assignment, or have a more clear explanation in the error message that you can't set an html attribute with a JSON object directly. return (
<ul>
{local_events.map(function(item) {
function createMarkup(item) { return {__html: item.description}; }
return <Child key={(item.time * Math.random())}> <div dangerouslySetInnerHTML={createMarkup(item)}/> <hr/> </li>
})}
</ul>
) |
On a side note, you shouldn't use random keys: #1342 (comment) |
The random key prevents React from doing any meaningful performance improvement. |
So I'm getting an error from babel when trying to use the DangerouslySet inner html for a div.
I'm using a gulpfile to watch my jsx files.
gulpfile:
So the problem is when I try to use the
__html:
in my code. It complains the tokens were unexpected.local_events
is an array that I'm mapping over to return list elements for each item in the list.item.description
is a string containing htmltags.
item.description
: "this is a paragraph that's not being interpreted as html but instead being rendered as literal text content which isn't what I was hoping
"Is this a React problem? Or is it Babel's linter? Stack trace is below.
The text was updated successfully, but these errors were encountered: