npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@qc/react-conditionals

v0.0.2

Published

A set of React components that conditionally renders its child components.

Downloads

1

Readme

@qc/react-conditionals

Build Status Coverage Status License Downloads

npm badge

A set of React components that conditionally renders its renderable children.

Installation

npm install --save @qc/react-conditionals

or

yarn add @qc/react-conditionals

Example Usage

import React from 'react'

import { Case, Else, If, Then, When } from '@qc/react-conditionals'


function SomeComponent(props) {
  return (
    <If is={status === 'active'}>
      <Then>
        <span>The status is active!</span>
      </Then>
      <Else>
        <span>The status is not active.</span>
      </Else>
    </If>
    <Case>
      <When is={status === 'active'}>
        <span>The status is active!</span>
      </When>
      <When is={status === 'pending'}>
        <span>The status is pending!</span>
      </When>
      <Else>
        <span>The status is unknown!</span>
      </Else>
    </Case>
    <When is={status === 'active'}>
      <span>The status is active!</span>
    </When>
  )
}

<If>

<If> may take as many <Then> or <Else> components as you like. The order of which does not matter.

<If is={status === 'active'}>
  <Then>
    This is rendered when If's condition is truthy.
  </Then>
  <Else>
    This is rendered when If's condition is not
    truthy.
  </Else>
  This will be rendered regardless of If's condition.
  That is, any renderable children outside of Thens or
  Elses will be rendered.
  <Else>
    This will also be rendered when condition is NOT truthy.
    That is, all immediate child Else components will be
    rendered when the condition is not true.
  </Else>
  <Then>
    This will also be rendered when If's condition is
    truthy.
  </Then>
</If>

<Case>

<Case> may take as many <When> components you like. It may optionally take one <Else> component. The order of the <When> and <Else> components in a <Case> is important. <When>s must come before the <Else>.

<Case>
  <When is={status === 'active'}>
    <span>The status is active!</span>
  </When>
  <When is={status === 'active'}>
    This will NOT be rendered.  Only the first When
    component with a truty condition will be rendered.
  </When>
  <When is={status === 'pending'}>
    <span>The status is pending!</span>
  </When>
  <Else>
    <span>The status is unknown!</span>
  </Else>
</Case>

Renderables between <When> and <Else> components are always rendered.

<Case>
  This is always rendered.
  <When is={...}>
    ...
  </When>
  <span>This is also always rendered.</span>
  <When is={...}>
    ...
  </When>
  <span>This is also always rendered.</span>
  <Else>...</Else>
  <span>This is also always rendered.</span>
</Case>

<When>

<When> can be used on its own outside of a <Case> parent component. It is equivalent to an <If>/<Then> combination.

<When is={status === 'active'}>
  This will be rendered when the condition is true.
</When>

Unsupported Usage

<Then> Outside of an <If>

<Then>
  This is not guaranteed to be rendered or not since it does
  not have an appropriate parent.
</Then>

<Else> Outside of a <Case> or an <If>

<Else>
  This is not guaranteed to be rendered or not since it does
  not have appropriate parents.
</Else>

<Else> before <When>

<Case>
  <Else>
    This is not guaranteed to be rendered or not since it
    comes before any &lt;When> components.  In fact, it
    may cause any successive &lt;When> components to not
    render.
  </Else>
  ...
</Case>

Other Packages from QC

Maintainers

License

ISC