`button-has-type` not recognizing default props
See original GitHub issueHi,
looks like whatever I try the button-has-type
rule can’t understand the default prop.
type Props = {
type: 'submit' | 'button' | 'reset',
};
function Button({ type, ...extraProps }: Props) {
return <button type={type} {...extraProps} />;
}
Button.defaultProps = {
type: 'submit',
};
error "null" is an invalid value for button type attribute react/button-has-type
type Props = {
type: 'submit' | 'button' | 'reset',
};
function Button({ type = 'submit', ...extraProps }: Props) {
return <button type={type} {...extraProps} />;
}
error "null" is an invalid value for button type attribute react/button-has-type
Issue Analytics
- State:
- Created 5 years ago
- Reactions:53
- Comments:27 (15 by maintainers)
Top Results From Across the Web
button-has-type not recognizing default props #1846 - GitHub
Hi, looks like whatever I try the button-has-type rule can't understand the default prop. type Props = { type: 'submit' | 'button' |...
Read more >Why are React defaultProps not passing values?
If I set default value when destructuring props like: { design: { size='md', color='black', outline, hover }, content, type, onClick } , it ......
Read more >12 essential ESLint rules for React - LogRocket Blog
react/require-default-props. Depending on the component, some props may be required while others are optional. If an optional prop is not passed ...
Read more >vue/require-default-prop
Rule Details #. This rule requires default value to be set for each props that are not marked as required (except Boolean props)....
Read more >eslint-plugin-react - npm
react/default-props-match-prop-types: Enforce all defaultProps are defined and not "required" in propTypes. react/destructuring-assignment: ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@truckingsim what i’d expect is that you’d have that Button component wrapped by SubmitButton and ResetButton components, and inside those you’d override the rule for the dynamic
type
- but you wouldn’t need that anywhere else.(ofc, this is separate from the issue that reset buttons are terrible UX and shouldn’t ever be on the page)
@ljharb In our component library at my company we have a Button component that is used for various things. We use a
oneOf
prop type to do an enum of type options and default to button since that’s the sane default. But the button can be used technically as a submit or reset button (and does get used).We have a component due to css and classes, its easier to have one shared one where the app people don’t have to worry about css classes and semantics, they can just use our Button.
I don’t want to turn this rule off, but if its going to be forced to be static, don’t really see another way.