3 ms·
simply adding required is all you need.Not required=true The omission is equal to required=false. No one really write required=true, they just add the attribute
by joshchernoff 2y ago
simply adding required is all you need.Not required=true The omission is equal to required=false. No one really write required=true, they just add the attribute `required` only by its self. This is one of the odd quarks about html attrs
Same is true for things like disabled ect
https://developer.mozilla.org/en-US/docs/Glossary/Boolean/HTML https://developer.mozilla.org/en-US/docs/Glossary/Boolean/HT...
> The strings "true" and "false" are invalid values. To set the attribute to false, the attribute should be omitted altogether. Though modern browsers treat any string value as true, you should not rely on that behavior.
in other words required=false may still end up making the field required. FYI.
- deathanatos 2y agoThey've written it in JSX, I think, not in HTML.
- Etheryte 2y agoThey've used `required={true}`, not `required="true"`, which is JSX, not HTML. The one with curlies isn't even valid HTML. In the old HTML spec, the correct value, if you wanted to set a value, was to set `required="required"`, but these days the spec is looser since it tries to conform to the web, not the other way around.
- joshchernoff 2y agoEven in jsx its not required to add a boolean value. Unless you are passing in a var as a prop in which case sure. But that didn't look like it was the case in these examples.
- ervine 2y agoOne of my favorite eslint rules to enable: https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-boolean-value.md https://github.com/jsx-eslint/eslint-plugin-react/blob/maste...
- everdimension 2y ago> Even in jsx its not required to add a boolean value Absolutely true! But I like to do it because I personally think it reads more nicely and is more explicit and that's what I do in all my projects. But it is indeed a matter of taste and I have nothing against code that follows the convention to omit the "true" value.