Skip to content

Instantly share code, notes, and snippets.

@chadmuro
Created October 18, 2021 13:05
Show Gist options
  • Save chadmuro/e51ad22b212b6f763c0632f4392b9039 to your computer and use it in GitHub Desktop.
Save chadmuro/e51ad22b212b6f763c0632f4392b9039 to your computer and use it in GitHub Desktop.
Controlled Component
import React, { useState } from "react";
const Controlled = () => {
const [inputText, setInputText] = useState("");
const handleSubmit = (e) => {
e.preventDefault();
console.log(inputText);
};
return (
<form>
<input
type="text"
value={inputText}
onChange={(e) => setInputText(e.target.value)}
/>
<button onClick={handleSubmit}>Submit</button>
</form>
);
};
export default Controlled;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment