Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use && operator to render JSX conditionally where possible #1422

Merged
merged 1 commit into from
Sep 30, 2024

Conversation

axelboc
Copy link
Collaborator

@axelboc axelboc commented Sep 26, 2024

I see a lot of ternaries in the JSX where the false branch renders null. This can often be simplified with the && operator. The only pitfall is that if the condition resolves to 0, then React happily renders that — otherwise, if it's an any other falsy value (empty string, false, null, etc.), it renders nothing.

So in this PR, I'm going over and refactoring all the cases that are 100% safe, and only those — that is, where the condition resolves necessarily to a boolean (===, >, !, etc.) For the rest, it will have to be done on a case-by-base basis (or after we migrate to TypeScript).

@marcus-oscarsson
Copy link
Member

That's nice, good initiative !

@marcus-oscarsson
Copy link
Member

marcus-oscarsson commented Sep 27, 2024

I can't seem to rebase this, from GitHub, can you do it @axelboc ?

@marcus-oscarsson marcus-oscarsson merged commit f6f5efe into develop Sep 30, 2024
16 checks passed
@marcus-oscarsson marcus-oscarsson deleted the ab-conditional-jsx branch September 30, 2024 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants