Reputation: 97
I have a variable
const linkElement = `Hey this is a link ${<a href="www.google.com">Click me!</a>} that can be clicked}`
This renders as Hey this is a link [Object object] that can be clicked.
How can I render this like, Hey this is a link Click me!(on click goes to google.com) that can be clicked
Upvotes: 3
Views: 1501
Reputation: 162
you would need to wrap your text inside a react component. A React component cannot be part of a string as it has no concept of a react component.
example:
LinkElement = () => <span>
Hey this is a link <a href="www.google.com">Click me!</a> that can be clicked
<span>
//and the place you want to use it
<LinkElement />
Upvotes: 2
Reputation: 58
You can do something like this
const linkElement = <>Hey this is a link<a href="www.google.com">Click me !</a> that can be clicked</>
Upvotes: 2