reactjs - way to embed if expressions inside JSX code? -


i guess stuff goes react tag must react tag or string; function returns tag or string; collection of tag or string or functions return them.

so if statement here not valid:

return <div>          if(something){            <projecttype typ={this.state.type} onchange={this.changetype}/>         }         , choice {type[this.state.type]}       </div>; 

so obvious way move if expression function maybe_render returns tag when condition met.

return <div>          maybe_render(something, this.state.type, this.changetype)         , choice {type[this.state.type]}       </div>; 

problem is, snippets have lots of calls functions have little logic. instead of 5-line snippet, may have 5-line snippet many calls extremely small functions.

what way embed if expressions inside jsx code?

i ternary if statements if there's not logic or cause re-use:

return (     <div>         {dosomething ? : null}         else     </div> ); 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -