Complete the code to update state correctly in a React functional component.
const [count, setCount] = useState(0); function increment() { setCount([1]); }
To update state by increasing the count, use count + 1 inside setCount.
Complete the code to run a side effect after the component updates.
useEffect(() => {
console.log('Count updated:', count);
}, [[1]]);The effect runs when count changes, so it must be in the dependency array.
Fix the error in the state update function to avoid stale state.
setCount([1] => [1] + 1);
Using a function with a parameter like prevCount ensures you get the latest state value.
Fill both blanks to create a controlled input that updates state on change.
const [name, setName] = useState(''); <input value=[1] onChange={e => setName([2])} />
e.value instead of e.target.value.The input's value is controlled by name. On change, update state with e.target.value.
Fill all three blanks to update multiple state values in an object using the spread operator.
const [form, setForm] = useState({ email: '', password: '' });
setForm({ ...[1], [2]: [3] });Use the spread operator on form to keep existing values, then update the password field with the new value from e.target.value.