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 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-maybe

v1.1.4

Published

Render one of two React components

Readme

react-maybe

Render one of two React components

Build Status

react-maybe is built behind a monad which conditionally displays one of two components based on the value contained in the of prop. If the value is one of null, undefined or false, the orElse component will be displayed. In all other cases the component passed to the either prop will be displayed.

The value in the of prop can be altered through the use map prop. The map prop could be a function or an array of functions. The value of of will be passed to the first map function, each additional map function will receive the return value of the previous one in the array. The return value of the last map funtion will then be used to determine which component to render.

Installation

Installation is currently available via npm:

$ npm i -S react-maybe

Usage

Basic

A basic react-maybe implementation will display one of two components based on the value of the of prop:

import Maybe from 'react-maybe';

const Component = ({ showChevronUp }) => (
  <div>
    <Maybe of={showChevronUp} either={<ChevronUp />} orElse={<ChevronDown />} />
  </div>
);
Advanced

A more advanced react-maybe implementation can alter the value of the of prop through use of the map prop:

import Maybe from 'react-maybe';

const sampleUser = { name: 'Maybe', isActive: false };
const isActive = user => user.isActive;

const Component = () => (
  <div>
    <Maybe of={sampleUser} map={isActive} either={<ActiveUser />} orElse={<InactiveUser />} />
  </div>
);

The above will render the orElse as our sample user is inactive

or

import Maybe from 'react-maybe';

const sampleUser = { name: 'Maybe', isActive: true };
const isActive = user => (user.isActive ? user : false);
const hasPhoneNumber = user => !!user.phone;

const Component = () => (
  <div>
    <Maybe
      of={sampleUser}
      map={[isActive, hasPhoneNumber]}
      either={<ActiveUserWithPhone />}
      orElse={<UserWithoutPhone />}
    />
  </div>
);

The above example will render the orElse component as our user is active, but has no phone number

Properties

  • of

    The value that the monad will contain.

  • map

    Accepts a function or an array of functions which has the ability to transform the value contained in the of prop.

  • either

    Accepts a component that will be rendered in all cases where the value of the of prop is not equal to undefined, null, or false.

  • orElse

    Accepts a component that will be rendered when the value of the of prop is equal to undefined, null, or false.

Running tests

You can either run the tests with npm or docker.

NPM
$ npm i
$ npm test
Docker
$ docker-compose run --rm app npm i
$ docker-compose up