Readdy Write
react ; if ;

React: If then in JSX

02.01.2023 (👁3086)

 

Wie kann man eine If-then Bedingung in React im Ausgabeblock einbringen?

 

<p>Keywords string: {this.state.keywords}</p>

<p>Keywords separate:                                   

{

this.state.keywords ?

 (this.state.keywords).split(";").map(keyword =>

 <a href={this.baseURL + "?k=" + encodeURI(keyword)} style={{ margin: '4px' }}>keyword</a>

)

:null

}

</p>

 

Ternari Ausdruck

Ein Bild, das Text enthält.

Automatisch generierte Beschreibung

Problem… ansonsten, wenn der Ausdruck null ist, entsteht ein javascript fehler und gar nichts wird ausgegeben


0,00 €