Skip to content

Instantly share code, notes, and snippets.

@jmoggridge
Created June 16, 2024 21:32
Show Gist options
  • Select an option

  • Save jmoggridge/e76a514d27fb665f115c7411d6c48c91 to your computer and use it in GitHub Desktop.

Select an option

Save jmoggridge/e76a514d27fb665f115c7411d6c48c91 to your computer and use it in GitHub Desktop.
Simplest react form: useRef
// using a useRef hook to manage form state with uncontrolled text area component
import { useRef } from 'react';
export default function TextInputForm() {
const ref = useRef();
const text = 'input';
function submitForm() {
console.log(ref.current);
}
return (
<form onSubmit={submitForm}>
<textarea id='txt' ref={ref} defaultValue={text}>
{ref.current}
</textarea>
</form>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment