Skip to content

Commit cd25f85

Browse files
chore: use ternaries instead of && in JSX (#90)
1 parent 80e07a7 commit cd25f85

File tree

17 files changed

+36
-38
lines changed

17 files changed

+36
-38
lines changed

.eslintrc.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,7 @@ module.exports = {
2323
"newlines-between": "always",
2424
},
2525
],
26+
27+
"react/jsx-no-leaked-render": [WARN, { validStrategies: ["ternary"] }],
2628
},
2729
};

_official-blog-tutorial/app/routes/join.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ export default function Join() {
108108
aria-describedby="email-error"
109109
className="w-full rounded border border-gray-500 px-2 py-1 text-lg"
110110
/>
111-
{actionData?.errors?.email && (
111+
{actionData?.errors?.email ? (
112112
<div className="pt-1 text-red-700" id="email-error">
113113
{actionData.errors.email}
114114
</div>
115-
)}
115+
) : null}
116116
</div>
117117
</div>
118118

@@ -134,11 +134,11 @@ export default function Join() {
134134
aria-describedby="password-error"
135135
className="w-full rounded border border-gray-500 px-2 py-1 text-lg"
136136
/>
137-
{actionData?.errors?.password && (
137+
{actionData?.errors?.password ? (
138138
<div className="pt-1 text-red-700" id="password-error">
139139
{actionData.errors.password}
140140
</div>
141-
)}
141+
) : null}
142142
</div>
143143
</div>
144144

_official-blog-tutorial/app/routes/login.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ export default function LoginPage() {
101101
aria-describedby="email-error"
102102
className="w-full rounded border border-gray-500 px-2 py-1 text-lg"
103103
/>
104-
{actionData?.errors?.email && (
104+
{actionData?.errors?.email ? (
105105
<div className="pt-1 text-red-700" id="email-error">
106106
{actionData.errors.email}
107107
</div>
108-
)}
108+
) : null}
109109
</div>
110110
</div>
111111

@@ -127,11 +127,11 @@ export default function LoginPage() {
127127
aria-describedby="password-error"
128128
className="w-full rounded border border-gray-500 px-2 py-1 text-lg"
129129
/>
130-
{actionData?.errors?.password && (
130+
{actionData?.errors?.password ? (
131131
<div className="pt-1 text-red-700" id="password-error">
132132
{actionData.errors.password}
133133
</div>
134-
)}
134+
) : null}
135135
</div>
136136
</div>
137137

_official-blog-tutorial/app/routes/notes/new.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ export default function NewNotePage() {
6969
}
7070
/>
7171
</label>
72-
{actionData?.errors?.title && (
72+
{actionData?.errors?.title ? (
7373
<Alert className="pt-1 text-red-700" id="title-error">
7474
{actionData.errors.title}
7575
</Alert>
76-
)}
76+
) : null}
7777
</div>
7878

7979
<div>
@@ -90,11 +90,11 @@ export default function NewNotePage() {
9090
}
9191
/>
9292
</label>
93-
{actionData?.errors?.body && (
93+
{actionData?.errors?.body ? (
9494
<Alert className="pt-1 text-red-700" id="body-error">
9595
{actionData.errors.body}
9696
</Alert>
97-
)}
97+
) : null}
9898
</div>
9999

100100
<div className="text-right">

_official-tutorial/app/routes/contacts.$contactId.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,17 @@ export default function Contact() {
5656
<Favorite contact={contact} />
5757
</h1>
5858

59-
{contact.twitter && (
60-
<p>
59+
{contact.twitter ? <p>
6160
<a
6261
target="_blank"
6362
href={`https://twitter.com/${contact.twitter}`}
6463
rel="noreferrer"
6564
>
6665
{contact.twitter}
6766
</a>
68-
</p>
69-
)}
67+
</p> : null}
7068

71-
{contact.notes && <p>{contact.notes}</p>}
69+
{contact.notes ? <p>{contact.notes}</p> : null}
7270

7371
<div>
7472
<Form action="edit">

client-side-validation/app/root.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@ export default function App() {
180180
<button>Submit</button>
181181
</div>
182182
</form>
183-
{actionData?.message && (
183+
{actionData?.message ? (
184184
<div className="result">{actionData.message}</div>
185-
)}
185+
) : null}
186186
</div>
187187
<ScrollRestoration />
188188
<Scripts />

combobox-resource-route/app/routes/index.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ export default function Index() {
4141
/>
4242

4343
{/* Add a nice spinner when the fetcher is loading */}
44-
{langs.state === "loading" && <Spinner />}
44+
{langs.state === "loading" ? <Spinner /> : null}
4545
</div>
4646

4747
{/* Only show the popover if we have results */}
48-
{langs.data && langs.data.length > 0 && (
48+
{langs.data && langs.data.length > 0 ? (
4949
<ComboboxPopover>
5050
<ComboboxList>
5151
{langs.data.map((lang, index) => (
@@ -55,13 +55,13 @@ export default function Index() {
5555
))}
5656
</ComboboxList>
5757
</ComboboxPopover>
58-
)}
58+
) : null}
5959
</Combobox>
6060
<p>
6161
<button type="submit">Submit</button>{" "}
62-
{searchParams.has("lang") && (
62+
{searchParams.has("lang") ? (
6363
<span>You submitted: {searchParams.get("lang")}</span>
64-
)}
64+
) : null}
6565
</p>
6666
</Form>
6767
);

firebase/app/routes/join.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default function Login() {
4646
return (
4747
<div>
4848
<h1>Join</h1>
49-
{actionData?.error && <p>{actionData.error}</p>}
49+
{actionData?.error ? <p>{actionData.error}</p> : null}
5050
<Form method="post">
5151
<input
5252
style={{ display: "block" }}

firebase/app/routes/login.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,7 @@ export default function Login() {
9393
return (
9494
<div>
9595
<h1>Login</h1>
96-
{(clientAction?.error || actionData?.error) && (
97-
<p>{clientAction?.error || actionData?.error}</p>
98-
)}
96+
{(clientAction?.error || actionData?.error) ? <p>{clientAction?.error || actionData?.error}</p> : null}
9997
<form method="post" onSubmit={handleSubmit}>
10098
<input
10199
style={{ display: "block" }}

gdpr-cookie-consent/app/root.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export default function App() {
4545
</head>
4646
<body>
4747
<Outlet />
48-
{!track && (
48+
{track ? null : (
4949
<div
5050
style={{
5151
backgroundColor: "#ccc",

0 commit comments

Comments
 (0)