How can I access the props when the page loads?

Viewed 57

I have the following code and I want to access the idOperand in the getRelationalOperators function but it is undefined

How can I access idOperand?

    class sample extends Component {
      constructor (props) {
        super()
        this.state = {
          idOperand: {},
        }
              this.getRelationalOperators = this.getRelationalOperators.bind(this);

      }
 componentDidMount(){
    this.getRelationalOperators();
  
  }
componentDidUpdate(prevProps) {
    if (prevProps.observationDetail !== this.props.observationDetail ) {
        this.setState({
            idOperand: this.props.observationDetail,
        })
    }
  getRelationalOperators() {

    var command = this.state.idOperand.Operand;
    
    GetRestrictionListService.getRelationalOperators(command, this.successRelationalOperators)
}
1 Answers

 class sample extends Component {
      constructor (props) {
        super(props)
        this.state = {
         idOperand: this.props.observationDetail
        }
              this.getRelationalOperators = this.getRelationalOperators.bind(this);

      }
 componentDidMount(){
    this.getRelationalOperators();
  
  }
componentDidUpdate(prevProps) {
    if (prevProps.observationDetail !== this.props.observationDetail ) {
        this.setState({
            idOperand: this.props.observationDetail,
        })
    }
  getRelationalOperators() {

    var command = this.state.idOperand.Operand;
    
    GetRestrictionListService.getRelationalOperators(command, this.successRelationalOperators)
}

Related