3 ms·
This is how I've come to write that in React, after giving up on attempting to find a consistent way to write ternaries which I would find acceptable when revis
by insin 10y ago
This is how I've come to write that in React, after giving up on attempting to find a consistent way to write ternaries which I would find acceptable when revisiting them (it just never happened):
let Home = ({location}) => <div>
<h2>HELLO</h2>
<p>Duis a turpis sed lacus dapibus elementum sed eu lectus.</p>
{!location.query.home && <p>No home query was specified.</p>}
{location.query.home && <p>You specified a home query: {location.query.home}</p>}
</div>
I usually put all the possible negative cases first because outside of micro-snippets they tend to be short and sweet compared to the positive condition.
- bestest 10y agoCome on people. It's so much simpler: return ( <div> <h2>hello</h2> { location.query.home ? <div>foo</div> : <div>bar</div> } </div> ) Or just replace that with a one-liner like, and put the respective code where it belongs: {location.query.home ? this.renderHomeStuff() : this.renderEtcStuff()} And simple ifs are obvious: <div> <h2>hey</h2> {foo && <div>foobar</div>} </div> Always strive to make your render methods simpler.