I'm wondering is it possible to update the button type between "submit" & "button" based on a boolean value: form?.hasErrors)
Here's my code:
const btnType = () => {
if (form?.hasErrors) {
return "submit";
}
return "button";
};
return (
<>
<StyledButton
onClick={!form?.hasErrors() ? handleShowModal : undefined}
type={btnType()}
>
Search
</StyledButton>
);
I basically just want to ensure that if the form has errors, that the button type is set to "submit" and if not, it will be set to "button" (default).
I don't know why you want this. But i think you can use this.
<StyledButton
onClick={!form?.hasErrors() ? handleShowModal : undefined}
type={form?.hasErrors() ? "submit": "button"}
>
Search
</StyledButton>