0

How to perform inline nested if Statement in React View ,

For example

true ? function a()  : function b() 

the Above format is working fine but i need to perform nested if like below example

For Example

true ? true : function a () :  true :function b()

My Working Code

  <div onClick={()=> this.props.materials.is_table_clicked  ? this.handleLocal() : this.props.enableMaterialTable(this.props.materials)}>

Tried Nested If but not Working

<div onClick={()=> this.props.materials.is_table_clicked  ? this.handleLocal() : this.props.audio.playing ? this.props.enableMaterialTable(this.props.materials)}>
2
  • I think you should avoid this, you lose so much readability. I'll put this into a dedicated function Commented Apr 16, 2017 at 17:08
  • they are newly made changes so i have to follow the same way Commented Apr 16, 2017 at 18:14

1 Answer 1

1

You are missing the else condition for nested else.

 : (this.props.audio.playing ? 
this.props.enableMaterialTable(this.props.materials):""//You missing this

It should work:

 <div onClick={()=> this.props.materials.is_table_clicked  ? 
    this.handleLocal() : (this.props.audio.playing ? 
this.props.enableMaterialTable(this.props.materials):"")}>
Sign up to request clarification or add additional context in comments.

3 Comments

Dont Work Ved :(
Great Ved ... it is the Solution ... :) Thanks for the time
Welcome @VickySmart.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.