You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But a clearer version would be to have an early return, when there is no shared parent component. This reduces unnecessary nesting, which often leads to large diffs. It also makes it easier easier to differentiate the conditional renders on the component level and the happy path.
I searched for such a rule, but didn't find anything existing. Therefore, I propose a new stylistic rule react/no-return-ternary. This rule would also match the code examples and documentation for conditional rendering in the React docs.
The text was updated successfully, but these errors were encountered:
Hmm… "cleaner" is pretty subjective there - i can see the ternary form being cleaner because the two blocks of jsx are aligned and the non-jsx boilerplate is minimal.
You might sometimes write a ternary at the top-level when returning from a React component
But a clearer version would be to have an early return, when there is no shared parent component. This reduces unnecessary nesting, which often leads to large diffs. It also makes it easier easier to differentiate the conditional renders on the component level and the happy path.
And of course it would still be valid to have ternaries that are not at top-level in a return.
I searched for such a rule, but didn't find anything existing. Therefore, I propose a new stylistic rule
react/no-return-ternary
. This rule would also match the code examples and documentation for conditional rendering in the React docs.The text was updated successfully, but these errors were encountered: