0.1.4 • Published 7 years ago

react-conditional-display v0.1.4

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

react-conditional-display 🌤⛅️🌥

Build Status

A react component that conditionally display the component's children elements in the UI.

The component is available on npmjs. Simply run:

npm install react-conditional-display

Props

NameRequiredDefaultTypeComment
ifYes-boolDetermines whether to render the principal children element(s).
elseNonullfunc, object (JSX)Alternative React component that would be rendered if if is false.
tagNodivstringThe HTML tag of the parent container if there are multiple children elements.
classNameNonullstringClass associated with the parent container if there are multiple children elements.

The component detects whether there are multiple children elements and will automatically wrap them in a div tag if no tag is provided. Otherwise, the sole child element would be rendered exactly as written.

Example Usage

import React, { Component } from 'react';
import Display from 'react-conditional-display';

class App extends Component {
  constructor(props) {
    super(props);
    this.state = {show: true}
    this.renderSomething = this.renderSomething.bind(this);
  }

  renderSomething() {
    return <h2>Hey! I am the alternative render!</h2>
  }

  render() {
    return (
      <div>
        <span>This will always show!</span>
        <Display
        if={this.state.show}
        else={this.renderSomething()}
        tag="section"
        className="center-modal">
          <h1>Hi friends!</h1>
          <div>I am the primary render!</div>
        </Display>
      </div>
    );
  }
}
export default App;

View on Codepen

Performance

As of version 0.0.4: BundlePhobia Screenshot of Performance

Contributions, Issues, and Changes

Please open an issue if you would like to contribute!

Acknowledgement

Thanks to Noel Broda's article on how to create and publish a React component on NPM!

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago