I have a React component named "Badge" returning some Text that is styled bold.
render() {
return (
<div>
<Text weight={'bold'}>
{this.props.label}
</Text>
</div>
)
Now, I use "Badge" in another component named "Card".
Because in Badge component all Text is styled bold, the whole sentence is bold as well:
return (
<div>
<Badge lable={'This part of the sentence is ' + 'normal font style' + ' and the rest is bold.'}></Badge>
</div>
)
Now, I would like to style the items in this element differently: I want to remove the bold style from 'normal font style' - only for this single part of the string. I already tried this way, but it doesn't work:
<Badge label={'This part of the sentence is ' + <span class=”normalText”>'normal font style'</span> + ' and the rest is bold.'}></Badge>
As an absolute beginner, this problem is driving me crazy. Any ideas how to solve this?
classNameinstead ofclass.weightprop to yourBadgeAPI, i.e.<Badge label='This is bolded text!' weight='bold' />Badgedo anything other than contain s div and aTextcomponent? Perhaps you could rewrite it a bit to be more of a container and it simply renders whatever children it contains (with whatever style they may have).dangerouslySetInnerHTMLwhich wouldn't work here as the Badge is only rendering a label into another react component). Why are you barred from modifyingBadge?