Sobes.tech
Junior — Senior

Detect an error when updating state in a React component

livecode

Task condition

In this code snippet, the setState function is used with a callback, but there is a logical error in calculating the new value of the property. It is necessary to carefully consider how the current state and property values are passed and how the update object is formed.

this.setState((previous, properties) => {
  return {
    streak: previous.streak + properties.count
  }
})

Explain what the error is and how to fix it, considering the rules of immutable state updates in React.