Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-only-when

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-only-when

> A declarative component for conditional rendering

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
18K
decreased by-12.99%
Maintainers
1
Weekly downloads
 
Created
Source

react-only-when

A declarative component for conditional rendering

NPM JavaScript Style Guide

Install

npm install --save react-only-when

Usage

import Only from 'react-only-when'

<Only when={true}>
  <h1>Here I Am</h1>
</Only>

Full Example

import React from 'react';
import Only from 'react-only-when'

class App extends React.Component {
  state = {
    show: true
  };

  toggle = () => this.setState(state => ({ show: !state.show }));

  render() {
    const { show } = this.state;
    return (
      <div className="app">
        <button onClick={this.toggle}>Toggle</button>
        <Only when={show}>
          <h1>Here I Am</h1>
        </Only>
      </div>
    );
  }
}

props

prop nametypedefaultisRequireddescription
childrenreact elementnulltrueA single child element
whenboolfalsetrueWhen true, children will rendered as is
hiddenModestring"withNull"falseDetermines how children should be hidden
classNamestring"r-o_hidden"falseThis is working in combination with hiddenMode={"withCss"}

hiddenMode enum

hiddenModedescription
"withNull"Will not render the child
"withDisplay"Will render the child with display:none
"withVisibility"Will render the child with visibility:hidden
"withCss"Will render the child with a CSS class (you can pass it a custom className prop)

License

MIT © sag1v

FAQs

Package last updated on 01 Aug 2018

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc