Q1. What are uncontrolled components?
Uncontrolled components store their own state internally in the DOM. You can access the values using refs when needed (e.g., on submit). They behave more like traditional HTML forms and require less code for simple cases.
Q2. How do you create an uncontrolled input?
Use a ref to access the DOM node. Example: const inputRef = useRef(null); const handleSubmit = () => { console.log(inputRef.current.value); }; return . defaultValue sets initial value.
Q3. When would you use uncontrolled components?
They are useful for simple forms where you only need values on submit, or when integrating with non-React code. They can also be more performant for very large forms because they don't re-render on each change.
Q4. What is the difference between defaultValue and value in uncontrolled components?
defaultValue sets the initial value, but after that, the input's value is managed by the DOM. If you set value, it becomes controlled. For uncontrolled, always use defaultValue (or defaultChecked for checkboxes).
Q5. How do you handle file inputs in React?
File inputs are always uncontrolled because their value is read-only. Use a ref to access the file(s) when needed. Example: , then fileRef.current.files.
