Skip to content

Instantly share code, notes, and snippets.

@chadmuro
Last active October 18, 2021 13:04
Show Gist options
  • Save chadmuro/d8b596e9cbbc328dbe65f650298b9eb6 to your computer and use it in GitHub Desktop.
Save chadmuro/d8b596e9cbbc328dbe65f650298b9eb6 to your computer and use it in GitHub Desktop.
Uncontrolled Component
import React, { useRef } from "react";
const Uncontrolled = () => {
const inputRef = useRef(null);
const handleSubmit = (e) => {
e.preventDefault();
console.log(inputRef.current.value);
};
return (
<form>
<input type="text" ref={inputRef} />
<button onClick={handleSubmit}>Submit</button>
</form>
);
};
export default Uncontrolled;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment