The two types of components describing form input processing in React.js are the Controlled and Uncontrolled Components. They are briefly described below.
import { useState } from "react";
const ControlledInput = () => {
const [inputValue, setInputValue] = useState("");
return (
<input
type="text"
value={inputValue}
onChange={(e) => setInputValue(e.target.value)}
/>
);
};
import { useRef } from "react";
const UncontrolledInput = () => {
const inputRef = useRef();
const handleSubmit = () => {
alert(`Input Value: ${inputRef.current.value}`);
};
return (
<>
<input type="text" ref={inputRef} />
<button onClick={handleSubmit}>Submit</button>
</>
);
};
Ready to transform your business with our technology solutions? Contact Us today to Leverage Our ReactJS Expertise.