How do I pass {currentyear} to label component?
let text = "<p><span>Year {currentyear}</span></p>";
<Label text={dangerouslySetInnerHTML={{__html: text}}}
Label is a component that takes in text as property and displays it on the document
This is just a literal string:
"<p><span>Year {currentyear}</span></p>"
It sounds like you're looking for a template literal:
`<p><span>Year ${currentyear}</span></p>`
This will evaluate the currentyear variable into the resulting string when first setting the text variable.
Edit: In a comment below you indicate that this string value comes from an external source:
"<p><span>Year {currentyear}</span></p>"
Which means it's a string and can't be a template literal. In that case you can simply perform your string replacement manually. For example:
let text = yourString.replace('{currentyear}', currentyear);
The point of all of this is that it's not really a question of "using a variable in dangerouslySetInnerHTML". You're already doing that (using the text variable). What you're trying to do is simply manipulate a string in JavaScript. There is a lot of string functionality you can use.
dangerouslySetInnerHTMLhere? If that is actual code and not just an example, it seems like you could just nest the labels content normally.