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

Proposal: using ! prefix on attributes to set them to false #134

Open
yuval-gilboa opened this issue Feb 3, 2022 · 0 comments
Open

Proposal: using ! prefix on attributes to set them to false #134

yuval-gilboa opened this issue Feb 3, 2022 · 0 comments
Labels
Proposal Proposals (haven't confirmed)

Comments

@yuval-gilboa
Copy link

yuval-gilboa commented Feb 3, 2022

According to current syntax, a JSX attribute without an initializer is set to boolean true.
However, there is no such shortcut equivalent for initializing an attribute for false so in this case the full form must be used explicitly.

My proposal is to allow an ! prefix before the attribute name as shortcut for false.

For example,

  • <MyComp visible/> is equivalent today to <MyComp visible={true} />
  • <MyComp !visible /> will become equivalent to <MyComp visible={false} />

This is quite a common case that is needed for JSX attributes whose default value is defined as true. It helps reduce unnecessary clutter and simplify JSX expressions.

This syntax extension is backward compatible with current grammar and can be added without impact on any existing JSX codebase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Proposal Proposals (haven't confirmed)
Projects
None yet
Development

No branches or pull requests

2 participants