react if else inside jsx code example
Example 1: jsx if block
render () {
return (
{(() => {
if (someCase) {
return (
someCase
)
} else if (otherCase) {
return (
otherCase
)
} else {
return (
catch all
)
}
})()}
)
}
Example 2: if else react render in jsc
const functionalComponent=()=> {
return (
{
props.isFeatured ? (
lol
) : ("")
}
);
}
Example 3: if else render react
render() {
const isLoggedIn = this.state.isLoggedIn;
return (
{isLoggedIn ? (
) : (
)}
);
}
Example 4: how to use if else inside jsx in react
renderElement(){
if(this.state.value == 'news')
return data;
return null;
}
render() {
return (
{ this.renderElement() }
)
}
Example 5: adding a if stement in jsx
render() {
return (
{this.state.value == 'news'? data: null }
)
}
Example 6: make a if in jsx
var loginButton;
if (loggedIn) {
loginButton = ;
} else {
loginButton = ;
}
return (
);