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
Post a Comment