New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

@axew/rc-if

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

@axew/rc-if

A react component for write if-else in render

latest
Source
npmnpm
Version
1.1.0
Version published
Maintainers
1
Created
Source

rc-if

Build Status

rc-if is a react component for writing if-else in render.

Usage

Install.

$ npm install @axew/rc-if
# or
$ yarn add @axew/rc-if

Example.

import { FI, If, ElseIf, Else } from '@axew/rc-if';

const App = () => {
  const { data, error, loading } = useFakeFetch('http://example.com');
  return (
    <FI>
      <h1>Title - this is always visible</h1>
      <If if={loading}>
        <Loading />
      </If>
      <ElseIf elseIf={error}>
        <Error message={error} />
      </ElseIf>
      <Else>
        <If if={data.list.length === 0}>
          <Empty />
        </If>
        <Else>
          <List dataSource={data.list} />
        </Else>
      </Else>
    </FI>
  );
};

Types

interface RcIF extends React.SFC<{ show?: boolean }> {
  If: React.SFC<{ if?: boolean }>;
  ElseIf: React.SFC<{ elseIf?: boolean }>;
  Else: React.SFC;
}

declare const FI: RcIF;

FI

The following components cannot work without FI wrapping. When use in nested, the following components can also be wrap.

PropertyDescriptionTypeDefault
showrender children or notbooleantrue

If

Render when if.

PropertyDescriptionTypeDefault
ifrender children or notboolean-

ElseIf

Render when elseIf.

PropertyDescriptionTypeDefault
elseIfrender children or notboolean-

Else

Render when else.

Keywords

react

FAQs

Package last updated on 12 Aug 2019

Related posts