Click here to Skip to main content
15,881,413 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to add html code in const using typescript?

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

What I have tried:

JavaScript
const sessionExpiredError = '<div> Your session has expired. Please login again via <a href="https://dev.com/UserTest" target="_blank">admin</a> </div>;';

const root = ReactDOM.createRoot(document.createElement('root'));

root.render(sessionExpiredError);

redirectToErrorPage(sessionExpiredError);
Posted
Updated 11-Apr-23 23:21pm
v3

1 solution

According to the documentation[^], the value passed to render should be an element, not a string.
JavaScript
const sessionExpiredError = (<div>Your session has expired. Please login again via <a href="https://dev.com/UserTest" target="_blank">admin</a></div>);

const root = ReactDOM.createRoot(document.createElement('root'));

root.render(sessionExpiredError);
 
Share this answer
 

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