News for hackers. Stuff that matters.
Re:Advice on JSX Conditionals by TameAntelope on Wednesday March 09, 2022 @11:38AM (#30616519)
I just avoid most of it by moving the complex conditional logic into a separate component and rendering that.

I don't think I've run into many issues with this strategy, and keeps my return statements nice and clean.

Re:Advice on JSX Conditionals by matt-attack on Wednesday March 09, 2022 @11:39AM (#30616538)
I find ternaries alone to be totally adequate.
Re:Advice on JSX Conditionals by TameAntelope on Wednesday March 09, 2022 @12:10PM (#30617043)
Oh they work, but stacking them tends to make future reading of the code harder due to their increased complexity.
Re:Advice on JSX Conditionals by kingdomcome50 on Wednesday March 09, 2022 @12:18PM (#30617179)
Nested ternaries can by structured to look a look like `if/else` if you put the `?/:` in the right spots.

It's a balance. Extracting logic into new components (and often new files!) isn't exactly ergonomic either.

I've found it's better to decrease readability if it makes understanding the logic more straight-forward (i.e. not hunting through several files to exhaust all possible outputs).

Re:Advice on JSX Conditionals by vlunkr on Wednesday March 09, 2022 @12:05PM (#30616955)
Agreed, if it's more complex than a single ternary, or && statements, make a new component.