State Management · Junior · Question 51 of 75
Does changing the argument of useState(initial) on later renders update the state?
function Price({ amount }) {
const [value, setValue] = useState(amount);
// amount changes from 10 to 20 - what is value?
}- ✓Correct answer: No - the initial value is used only on the first render;
valuestays 10 - 2Yes - state always follows the argument
- 3Yes, but only in Strict Mode
Explanation
React keeps state between renders and ignores the argument afterwards. If the component should follow the prop, use the prop directly or reset with a key.