Skip to content

Instantly share code, notes, and snippets.

@Uvacoder
Forked from jmoggridge/simple-form-useref.jsx
Created June 16, 2024 21:58
Show Gist options
  • Select an option

  • Save Uvacoder/6bc93252d8b59807f9f5af045b2b73a3 to your computer and use it in GitHub Desktop.

Select an option

Save Uvacoder/6bc93252d8b59807f9f5af045b2b73a3 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