reactjs - What are the conditional operators we can use in react js under render method? -
i want perform logic using switch or or if loop .but cannot use of in render method.right using ternary operator.is there other operators can access in render method?
use inline function. demo: https://jsfiddle.net/viviancpy/7v9th3lj/1/
<div id="container"> <!-- element's contents replaced component. --> </div> var hello = react.createclass({ render: function() { return ( <div> {(() => { switch (this.props.name) { case "world": return (<div>oh hello world</div>); default: return (<div>good morning</div>); } })()} </div> ); } }); reactdom.render( <hello name="world" />, document.getelementbyid('container') );
Comments
Post a Comment