Skip to content
Discussion options

You must be logged in to vote

I think I can answer my own question here but will still open to hear any other solutions from the community.

My goal in all of this is to create custom form elements that will behave just like native form elements (ie input, textarea, select) where the developer can put it inside a <Form> and expect Form submissions, Form.onChange and Form.onReset to just work™️ .

Form submissions

For this I think the path is pretty clear: use hidden inputs:

function MyCustomFormElement = () => {
  const [value, setValue] = useState('')

  return (
    <>
      <SomeStatefulFormComponent value={value} onChange={setOnChange} />
      {/* tip: can use <textarea /> instead if you need to preserve new lines*/}

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@seanlennaerts
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by seanlennaerts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants