how to put if condition in react js code example
Example 1: 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.
Example 2: adding a if stement in jsx
render() {
return (
{this.state.value == 'news'? data : null }
)
}