0

I have a requirement where in I have to set the initial state value of the state based on the other state value in class based component.

  this.state = {
      element1: false,
      element2: element1 ? "show": "hide"
   }
Wasif
  • 183
  • 2
  • 3
  • 14
  • If the requirement is only for initial value "based on the other state value" then you can assume `element1` to be `false`. If `element2` is always calculated based on `element1` just do not keep it in state, compute it in place. – Yury Tarabanko Jan 26 '23 at 17:53

0 Answers0