
Security News
Open Source CAI Framework Handles Pen Testing Tasks up to 3,600× Faster Than Humans
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
react-toggle-display
Advanced tools
A stateless react component that toggles the display of it's children. It's like ng-show
, ng-hide
or ng-if
but for react.
This allows you to DRY up statements like this:
<div className={this.props.shouldHide ? 'hidden' : ''}>
Example usage:
import React, { Component } from 'react';
import ToggleDisplay from 'react-toggle-display';
class App extends Component {
constructor() {
super();
this.state = { show: false };
}
handleClick() {
this.setState({
show: !this.state.show
});
}
render() {
return (
<div className="App">
<p className="App-intro">
<button onClick={ () => this.handleClick() }>Toggle things</button>
</p>
<ToggleDisplay show={this.state.show}>
I am rendered in a span (by default) and hidden with display:none when show is false.
</ToggleDisplay>
<ToggleDisplay if={this.state.show} tag="section">
I am rendered in a section and removed from the DOM when if is false.
</ToggleDisplay>
</div>
);
}
}
export default App;
hide
- boolean
show
- boolean
if
- boolean
tag
- string. The tag name to use as the ToggleDisplay element. Defaults to span.
The two first props are simply the inverse of each other. Using both at the same time will result in canceling each other out.
npm install react-toggle-display
To run tests: npm test
Big thanks to willgm for his contributions.
Note that if you are using a version under 0.1.1, you will have to compile react-toggle-display's JSX yourself. I recommend just updating to 1.x so you don't have to worry about that. No breaking API changes in 1.x.
While v2 does not change anything functionally, it was refactored to be a "stateless functional component", which won't work in React versions less than 0.14.
v2.2 adds the prop-types
package to get rid of some warnings when using React 15.5
FAQs
Hide/show a component's children
The npm package react-toggle-display receives a total of 562 weekly downloads. As such, react-toggle-display popularity was classified as not popular.
We found that react-toggle-display 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
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.