Q. What is the correct way to update state based on the previous state?

  • (A) setState(newState)
  • (B) setState(prevState => newState)
  • (C) this.state = newState
  • (D) state = newState
πŸ’¬ Discuss
βœ… Correct Answer: (B) setState(prevState => newState)
Explanation: Using a function with prevState ensures you update based on the latest state.
Explanation by: Mr. Dubey
Using a function with prevState ensures you update based on the latest state.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
109
Total Visits
πŸ“½οΈ
1 y ago
Published
πŸŽ–οΈ
Mr. Dubey
Publisher
πŸ“ˆ
82%
Success Rate