lost9123193 lost9123193 - 2 months ago 17
React JSX Question

JSX with Html Tag in React

Is there a way to incorporate react and an href tag?

The id:

{this.state.id}


The html tags:

href="#demo1"
id="demo1"


Is there a way I can add the state Id to the html tag to get something like this?

href = {" #demo + {this.state.id} "}

Answer

You're almost correct, just misplaced a few quotes. You can do:

href={'#demo' + this.state.id}

This will use the string #demo and concatenate it to this.state.id.

Comments