New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

if-else-react

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

if-else-react

small helper component for conditional rendering

latest
Source
npmnpm
Version
0.5.6
Version published
Maintainers
1
Created
Source

if-else-react · npm

Small helper component for conditional rendering.

This

render() {
  const isLoggedIn = this.state.isLoggedIn;
  return (
    <div>
      {isLoggedIn ? (
        <span>
          <Button onClick={this.handdleSettingsClick}>Account Settings</Button>
          <Button onClick={this.handleLogoutClick}>Logout</Button>
        </span>
      ) : (
        <span>
          <Button onClick={this.handleLoginClick}>Login</Button>
          <Button onClick={this.handleSignUpClick}>Sign Up</Button>
        </span>
      )}
    </div>
  );
}

becomes this ✨

render() {
  const isLoggedIn = this.state.isLoggedIn;
  return (
    <div>
      <If condition={isLoggedIn}>
        <Button onClick={this.handdleSettingsClick}>Account Settings</Button>
        <Button onClick={this.handleLogoutClick}>Logout</Button>
        <Else />
        <Button onClick={this.handleLoginClick}>Login</Button>
        <Button onClick={this.handleSignUpClick}>Sign Up</Button>
      </If>
    </div>
  );
}

Getting Started

Install via npm:

$ npm install if-else-react --save

and then just import it in your app

import If, { Else } from 'if-else-react';

and use it like shown in the example above. done 🎉

The If Component

The If Component is only rendering whats inside if the condition prop is true.
If there is a Else component as a direct children then all children components after the Else will be rendered if the condition is false.

Props
PropTypeDefaultRequired?
conditionbooleanundefinedno

The Else Component

The Else Component renders and does nothing by itself. But when used inside of a Ifthen it seperates what is rendered based on the condition passed into the If.

Props
PropTypeDefaultRequired?
----

Keywords

react

FAQs

Package last updated on 13 Oct 2020

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