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?
}

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.

Further reading

Problem with a question

State Management · Junior · question 51

Test yourself

Take the State Management · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz