-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
In Card.tsx, there is both a handleSubmit and isValid props. The caller can provide contradictory props like { isValid: false, handleSubmit: () => { send(strangeValue); } }, where strangeValue can be a default causing unexpected outcomes, or a runtime error.
My proposal here would be to provide handleSubmit as an optional prop, and absence implicitly means invalidity.
On a practical level, this reduces implementations like this (parsedValue comes from the implementation of NumberInput, where public component parses the value of a text input):
<Card
handleSubmit={() => {
if (parsedValue !== null) {
props.handleSubmit(parsedValue);
}
}}
isValid={parsedValue !== null}
/>to this (pardon the syntax here, could be written nicer with the callback pulled out top level):
<Card
handleSubmit={parsedValue && (() => {
if (parsedValue !== null) {
props.handleSubmit(parsedValue);
}
})}
/>This blog post is a much better explanation for all of this.
johnrees
Metadata
Metadata
Assignees
Labels
No labels