react conditional return component code example
Example 1: how to use if else inside jsx in react
renderElement(){
if(this.state.value == 'news')
return data ;
return null;
}
render() {
return (
{ this.renderElement() }
)
}
Example 2: react native conditional rendering
class Component extends React.Component {
const a = true
render() {
return (
{a == true
? ()
: null
}
)
}
}
This is staying: if a == true, render a button component.
Otherwise render null, in other words nothing.