Click here to Skip to main content
15,887,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to use href tag using const in react.

I tried below code but getting html code also. I want display only text message 

const ExpiredMesaage =
  'Your session has expired. Please login again via <a href="https://www.google.com/" target="_blank"> Google</a>.'


What I have tried:

const ExpiredMesaage =
  'Your session has expired. Please login again via <a href="https://www.google.com/" target="_blank"> Google</a>.'
Posted
Updated 11-Apr-23 9:59am

1 solution

That is a plain string, so React will render it on the DOM as it is. You can render the hyperlink inside a paragraph.

Use this:
JavaScript
const ExpiredMesaage =
  <p>Your session has expired. Please login again via <a href="https://www.google.com/" target="_blank"> Google</a>.</p>
When you render this on the UI, you should see a paragraph with a link.
 
Share this answer
 
Comments
ramweb12345 12-Apr-23 2:14am    
I tired the below code not working, they displaying with code, need to display only text.

const sessionExpiredError =
' Your session has expired. Please login again via Admin .';

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900