I have a React component called "ExplanationLists", I would like to add dynamic inline style into li
html element with css pseudo code li::after
, the way I can style the bullet-point with graphic better. For example,
li::before {
content: dynamic_content;
}
However, I couldn't really make it happen. Any suggestion would be appreciated.
Below is the code I've written.
class ExplanationLists extends Component{
populateHtml(){
// asign lists data into variable "items"
var items = this.props.items;
// loop though items and pass dynamic style into li element
const html = items.map(function(item){
var divStyle = {
display: "list-item",
listStyleImage:
'url(' +
'/images/icons/batchfield_fotograf_rosenheim_icon_' +
item.icon +
'.png' +
')'
};
// html templating
return (
<li style={divStyle}>
<h3 >{item.title}</h3>
<p>{item.desc}</p>
</li>
);
});
// return html
return html;
}
render(){
return (
<ul>
{this.populateHtml()}
</ul>
)
}
}
In your particular case you can use data
attributes.
li::before {
content: attr(data-content);
}
render = () => <li data-content={this.props.content}>{this.props.children}</li>