-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
propType [name] is not required, but has no corresponding defaultProp declaration #1433
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
Comments
I would say this is as expected. Since the prop is not required, you should specify a default value. You can decide to set it to |
I see. Thank you |
I didn't understand what should I do in my case (it's also shows eslint error: propType "isSmall" is not required, but has no corresponding defaultProp declaration. (react/require-default-props)): type SwitcherProps = {
isChecked: boolean,
action: () => void,
isSmall?: boolean
}
export const Switcher = (props: SwitcherProps) => {
return (
<label className={"switcher ".concat(props.isSmall ? "small" : "")}>
<input type="checkbox" checked={props.isChecked} className="input" />
<span role="presentation" className="slider" onClick={props.action} />
</label>
);
}; |
@AlexanderNaiden add: Switcher.defaultProps = {
isSmall: false,
}; |
The error message is confusing because it's singular instead of plural. (and... #2063 was posted just 2 hours ago!) |
I fixed this issue using the default prop static defaultProps = {
actions: {
function_name: () => null,
},
} |
I am using Flow for type checking, and I have something like this:
So, my question is, should I get this linting error? Is this the desired behavior?
The text was updated successfully, but these errors were encountered: