-
Notifications
You must be signed in to change notification settings - Fork 14
Closed
Description
I was playing with this plugin a bit, and this is very related to #7, I don't like excessive indentation for a simple if else statement in JSX. I use prettier, and maybe there could be something changed there as well, but look at this. I have a button here:
<div className="col">
<button className="btn btn-info btn-lg" onClick={this.endTimer}>
End timer
</button>
<div>Now I realise, that, before I end the timer, I need to check if the timer is started. So I use an if else construct:
<div className="col">
{
do {
if (timer == null) {
<button className="btn btn-info btn-lg" onClick={this.startTimer}>
Start Timer
</button>;
} else {
<button className="btn btn-danger btn-lg" onClick={this.endTimer}>
End Timer
</button>;
}
}
}
</div>Suddenly, the button is 6 spaces more indented! And a lot of more extra visual noise. Now since keywords like if, switch, for, try can't be used in an expression context, can't we automatically (behind the scenes), make a do expression construction of this if we encounter such keywords in a expression context. What I mean, could we allow to write the above like this:
<div className="col">
{if (timer == null) {
<button className="btn btn-info btn-lg" onClick={this.startTimer}>
Start Timer
</button>;
} else {
<button className="btn btn-danger btn-lg" onClick={this.endTimer}>
End Timer
</button>;
}}
</div>sindresorhus, haltcase, kgtkr, krzkaczor, pitaj and 22 more
Metadata
Metadata
Assignees
Labels
No labels