seas-computing / seas-computing/mark-one
React does not recognize the `submitHandler` prop on a DOM element error
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 0
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
Description
The Form component is implemented in such a way that it simply returns styled.form, which is effectively the same as:
return (<form> </form>)
In turn this means that when the submitHandler prop is passed to the component at runtime is equivalent to:
return (<form submitHandler={() => {}}> </form>)
since submitHandler is not a valid prop on HTMLFormElement, this causes the following error to be thrown:
Warning: React does not recognize the `submitHandler` prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase `submithandler` instead. If you accidentally passed it from a parent component, remove it from the DOM element.
form
O@webpack-internal:///./node_modules/styled-components/dist/styled-components.browser.esm.js:32:23472
div
O@webpack-internal:///./node_modules/styled-components/dist/styled-components.browser.esm.js:32:23472
KioskEntryPage@webpack-internal:///./src/client/components/pages/KioskEntryPage.tsx:92:46
RenderedRoute@webpack-internal:///./node_modules/react-router/dist/index.js:580:7
Routes@webpack-internal:///./node_modules/react-router/dist/index.js:1269:7
AppRouter
main
O@webpack-internal:///./node_modules/styled-components/dist/styled-components.browser.esm.js:32:23472
tt@webpack-internal:///./node_modules/styled-components/dist/styled-components.browser.esm.js:32:20266
MarkOneWrapper@webpack-internal:///./node_modules/mark-one/lib/Theme/MarkOneWrapper.js:11:20
Router@webpack-internal:///./node_modules/react-router/dist/index.js:1208:7
BrowserRouter@webpack-internal:///./node_modules/react-router-dom/dist/index.js:697:7
App
To Reproduce
- Import the Form component
- Render it (passing the
submitHandlerprop is optional, the error occurs either way).
Expected Behavior
The component should render without error in the console, and the submitHandler function should be fired on form submit.
Actual Behavior
The above error was raised and the submitHandler function is not fired on form submit.
Screenshots
Additional Information
Possible solution may be to (instead) return a rendered version of the component in a similar manner to the Button component:
const Form: FunctionComponent<FormProps> = (props): ReactElement => {
const {
id,
submitHandler,
label,
children,
} = props;
const theme = useContext(ThemeContext);
return (
<Form
id={id}
label={label}
submitHandler={submitHandler}
>
{ children }
</Form>
);
};
)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Form component under src/Forms and compare its rendering to src/Buttons/Button.tsx, which the issue identifies as a similar component. Reproduce the warning by rendering Form with and without submitHandler, then verify that the console error is gone and submitHandler fires on form submission.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100