Severity: AnalysisErrorSeverity.WARNING
Maturity: stable
Since 1.0.0
While any thrown errors/exceptions are caught by React and surfaced as prop warnings, throwing is not recommended.
Return the error instead.
GOOD:
class FooComponent extends UiComponent2<FooProps> {
@override
get propTypes => {
keyForProp((p) => p.prop1): (props, info) {
if (props.prop1 == null) {
return PropError.required(info.propName);
} else if (props.prop1 > 0) {
return PropError.value(props.prop1, info.propName);
}
return null;
},
};
}
BAD:
class FooComponent extends UiComponent2<FooProps> {
@override
get propTypes => {
keyForProp((p) => p.prop1): (props, info) {
if (props.prop1 == null) {
throw PropError.required(info.propName);
} else if (props.prop1 > 0) {
throw PropError.value(props.prop1, info.propName);
}
return null;
},
};
}