chandra kumar
chandra kumar

Reputation: 105

how can we check if condition in reactjs

handleClick=()=>{
    console.log("final course values"+ " "+this.state.selectCourseValue)

    console.log("selected teacher"+ " "+this.state.selectedTeacher)
    if(this.state.selectCourseValue ===null  && this.state.selectedTeacher !== undefined)
    {
        console.log("please select")
        message.warning('Add course')
        return;
    }
    else{
        console.log("Sucessfully updated")

    }
}

Upvotes: 0

Views: 45

Answers (1)

Sulthan
Sulthan

Reputation: 130132

If selectCourseValue is an array, then your condition should be probably this:

if (this.state.selectedTeacher && (this.state.selectCourseValue || []).length === 0) {
}

Checking that selectedTeacher is not empty and selectCourseValue is empty.

Upvotes: 1

Related Questions