
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
react-if-component
Advanced tools
Render React components conditionally.
This component helps you turn this
render: function() {
return (
<div>
<Header />
{this.renderBody()}
</Footer>
</div>
);
},
renderBody: function() {
return (this.props.age >= this.props.drinkingAge)
? <span class="ok">Have a beer, {this.props.name}!</span>
: <span class="not-ok">Sorry {this.props.name } you are not old enough.</span>;
}
into this
render: function() {
return (
<div>
<Header />
<If when={ this.props.age >= this.props.drinkingAge }>
<Then><span class="ok">Have a beer, {this.props.name}!</span></Then>
<Else><span class="not-ok">Sorry {this.props.name}, you are not old enough.</span></Else>
</If>
</Footer>
</div>
);
}
With this approach to conditional elements, children of either branch will always be evaluated no matter what. This can be an issue eg. if you're testing an object for nullity, and then try to access one of its property inside of the Then branch. See this StackOverflow discussion as well as issue #1 for more informations.
npm install react-if-component
// Browserify:
var If = require('react-if');
// Otherwise
var If = ReactIf;
var Stage1 = React.createClass({
render: function() {
return (<div>Stage1</div>);
}
});
var Stage2 = React.createClass({
render: function() {
return (<div>Stage2</div>);
}
});
var Beer = React.createClass({
getInitialState: function() {
return {
stage: true
};
},
changeStage() {
this.setState({ stage: !this.state.stage })
},
render: function() {
return (
<div id="some-id">
<button onClick={ this.changeStage }>Change Stage</button>
<If when={ this.state.stage }>
<Stage1 />
</If>
<If when={ !this.state.stage }>
<Stage2 />
</If>
</div>
)
}
});
React.renderComponent(
<Beer />,
document.getElementById('example')
);
| Property | Type |
|---|---|
when | Boolean |
If when evaluates to true, renders the children block will be rendered, otherwise renders the null block.
React If Component is released under the MIT license.
FAQs
Render React components conditionally.
We found that react-if-component demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.