Readdy Write  
0,00 €
Your View Money
Views: Count
Self 20% 0
Your Content 60% 0

Users by Links 0
u1*(Content+Views) 10% 0
Follow-Follower 0
s2*(Income) 5% 0

Count
Followers 0
Login Register as User

✅ React IF Else in Render()

02.03.2021 (👁5259)

Wie erstellt man ein bedingtes Rendern von HTML Elementen in React mit IF ELSE ?

Aufgabe:

Folgender HTML Link Button soll in React nur angezeigt werden, wenn eine Bedingung erfüllt ist.

<Link to={"//" + this.state.idarticle}>

  <Fab color="secondary" aria-label="edit" style={float: 'right' }}>

   <EditIcon />

  </Fab>

</Link>

 




 

 

Lösung:

Man erstellt einen Geschweiften Klammer und dann ? (true) : (false) Code in React

 

React Muster

 {

  this.state.variable ?

  (

    xxx

  )

  :

  (

    <></>

   )

 }

 

 

 

React IF Else Code in Render

 {

  this.state.isowner ?

  (

    <Link to={"//" + this.state.idarticle}>

      <Fab color="secondary" aria-label="edit" style={float: 'right' }}>

        <EditIcon />

      </Fab>

    </Link>

  )

  :

  (

    <></>

   )

 }