Do not forget to correct the name of the component, it should begin with capital letters .
<h / "> The conditions are not related to JSX , as indicated in other comments and answers. That is how JavaScript works.
Please note that it is important to remember:
Never do double equal ( == ) aka "Abstract equality" against boolean, This requires errors.
Because the engine will only apply type coercion to a logical value, which can lead to unexpected behavior.
For instance,
if(2 == true) //returns false
and
if(2 == false) // returns false
from spec :
If type (x) is Boolean, return the result of the comparison! ToNumber (x) == y.
If type (y) is Boolean, return the result of the comparison x ==! ToNumber (y).
Instead, you can perform an implicit check:
if (this.props.signedIn)
Or an explicit check, but using a triple equals aka "strict equality"
if (this.props.signedIn === false)
<h / "> Regarding the react part: Again, these are basically just JavaScript functions and objects.
When you do not miss prop then there will be undefined :
this.props.signedIn
So, the implied check as above:
if (this.props.signedIn)
Will work fine.
<h / "> Running the example without gaps:
class MyComponent extends React.Component { render() { if (this.props.signedIn) { return <h1>Hi</h1>; } return <h1>not signed on!</h1>; } } ReactDOM.render( <MyComponent />, document.getElementById('root') );
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script> <div id="root"></div>
The execution example with false passed to:
class MyComponent extends React.Component { render() { if (this.props.signedIn) { return <h1>Hi</h1>; } return <h1>not signed on!</h1>; } } ReactDOM.render( <MyComponent signedIn={false}/>, document.getElementById('root') );
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script> <div id="root"></div>
Example run with true passed to:
class MyComponent extends React.Component { render() { if (this.props.signedIn) { return <h1>Hi</h1>; } return <h1>not signed on!</h1>; } } ReactDOM.render( <MyComponent signedIn={true}/>, document.getElementById('root') );
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script> <div id="root"></div>