Proposal: using ! prefix on attributes to set them to `false`
yuval-gilboa opened this issue · comments
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.