ternary operator react
render () {
return (
<div className="row">
{ //Check if message failed
(this.state.message === 'failed')
? <div> Something went wrong </div>
: <div> Everything in the world is fine </div>
}
</div>
);
}<img
src={this.state.photo}
alt=""
style={ isLoggedIn ? { display:'block'} : {display : 'none'} }
/>
// or
<img
src={this.state.photo}
alt=""
style={ { display: isLoggedIn ? 'block' : 'none' } }
/>render() {
const isLoggedIn = this.state.isLoggedIn;
return (
<div>
The user is <b>{isLoggedIn ? 'currently' : 'not'}</b> logged in.
</div>
);
}function Mailbox(props) {
const unreadMessages = props.unreadMessages;
return (
<div>
<h1>Hello!</h1>
{unreadMessages.length > 0 &&
<h2>
You have {unreadMessages.length} unread messages.
</h2>
}
</div>
);
}render() {
const isLoggedIn = this.state.isLoggedIn;
return (
<div>
The user is <b>{isLoggedIn ? 'currently' : 'not'}</b> logged in. </div>
);
}Condition ? Block_For_True : Block_For_False
Also in JavaScript:
- store console.timeEnd in variable js
- javascript stringify blob
- vendor bundle base js and bootstrap min js conflict
- how to make 1st letter capital in ejs
- keyup function in jquery
- ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'ngIf: [object Object]'. Current value: 'ngIf: true'.
- node js express
- close exit app react native
- format currency javascript
- how to smooth scroll in javascript
- react admin newrecords.foreach is not a function
- scroll jquery to anchor
- go back doesnt load javascript safari
- check unique object in array javascript site:stackoverflow.com
- stopper un intervalle javascript
- toastify js
- js insert in array
- jquery validation plugin
- angular event scroll end of page
- open lightbox in backend
- js clone array
- how to import js via script in react
- node js TypeError [ERR_INVALID_ARG_TYPE]: The argument must be of type string. Received undefined
- node_modules/react-native-paper/lib/module/core/Provider.js