add condion in jsx 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: javascript in jsx
const name = 'Josh Perez';
const element = Hello, {name}
;
//notice the use of {...} to jump from jsx to javascript.
ReactDOM.render(
element,
document.getElementById('root')
);