Q1. How are forms handled in React?
Forms in React can be controlled or uncontrolled. In controlled components, form data is handled by the component's state. In uncontrolled components, the DOM itself handles the form data, using refs to access values.
Q2. What is a controlled component?
A controlled component is an input element whose value is controlled by React state. The value is set from state, and an onChange handler updates the state. This makes React the single source of truth, enabling instant validation and dynamic inputs.
Q3. What is an uncontrolled component?
An uncontrolled component stores its own internal state in the DOM. You can access the value using a ref (useRef) when needed, like on form submission. This is similar to traditional HTML forms but less integrated with React.
Q4. How do you handle multiple inputs in a form?
You can use a single state object and a single onChange handler that uses the input's name attribute to update the correct field. For example: const [form, setForm] = useState({}); const handleChange = (e) => setForm({...form, [e.target.name]: e.target.value});
Q5. How do you handle form submission?
Attach an onSubmit handler to the
