Want to use ternary operator in jsx to include html with react? I currently like to format my ternaries like this in react:
1 2 3 4 5 6 7 8 9 10 11 | 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> ); } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.