I am trying to display a json list with html tags in a row in a list as follows jsbin . He works at Jsbin. But in my console, I got the warning below:
warning Only set one of `children` or `props.dangerouslySetInnerHTML` react/no-danger-with-children
just wondering if there is another way to render a list with a danger of SetInnerHTML to avoid a warning?
const displayList = [
{
item: 1,
text: "<strong>ABC</strong> this should be strong."
},
{
item: 2,
text: "<a>ABC</a> this should be link."
},
{
item: 3,
text: "normal text"
}
];
const App = () => (
<ul>
{displayList.map((item, i) => (
<li key={i}>
<div dangerouslySetInnerHTML={{
__html: item.text
}}>
</div>
</li>
))}
</ul>
);
ReactDOM.render(
<App />,
document.getElementById('root')
);
source
share