-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Eugene Chen
authored and
Eugene Chen
committed
Jun 24, 2021
1 parent
16c3df8
commit a07ad38
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
## Disallow && condition inside JSX Embed. (react/jsx-embed-condition) | ||
This rule disallows use of && inside JSX Embeds to avoid conditional numbers from being rendered. | ||
|
||
## Why? | ||
Here is an [acrticle](https://kentcdodds.com/blog/use-ternaries-rather-than-and-and-in-jsx) explaining the problems that can happen when you use && to conditionally render content in JSX. | ||
|
||
## Rule Details | ||
Examples of incorrect code for this rule: | ||
|
||
<div> | ||
{x && <MyProfile />} | ||
</div> | ||
<div> | ||
{x || y && <strong>Hello</strong>} | ||
</div> | ||
Examples of correct code for this rule: | ||
|
||
<div> | ||
{x ? <MyProfile /> : null} | ||
</div> | ||
// -- | ||
<div> | ||
{x || y ? <strong>Hello</strong> : null} | ||
</div> |