0

I face this issue so many time, dealing with nested object.

this.props.something.something2

Above statement is dangerious, it can took my entire application, simply because I didn't aware of this.props.something can be optional. How to do checking in such case?

Alan Jenshen
  • 3,159
  • 9
  • 22
  • 35

1 Answers1

0

Before accessing to 'something2' of this.props.something, you should check the existing of 'something' first.

if(this.props.something) {
   alert(this.props.something.something2);
 }
Tran Ho
  • 1,442
  • 9
  • 15