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

react-control-flow-components

v1.2.1

Published

Control flow components for React

Downloads

12

Readme

react-control-flow-components

Control flow components for React to make writing JSX more natural.

Build Status

import React from 'react';
import { Case, ForEach, If, Switch } from 'react-control-flow-components';

<If test={ condition }>
    <span>Only if true</span>
</If>

<Switch test={ condition }>
    <Case value="first">
        <span>If condition matches 'first'</span>
    </Case>
    <Case value="second">
        <span>If condition matches 'second'</span>
    </Case>
</Switch>

<ForEach items={ data }
         component={ DataView } />

Installation

Install with npm or yarn

npm install --save react-control-flow-components

Documentation

<If />

<If test={ condition }>
    <span>Only if true</span>
</If>

Prop | Type | Notes ---- | ---- | ----- test | Boolean | The expression to evaluate. Contents are rendered if the expression evaluates to truthy.

Note that children are evaluated by React before being passed to <If /> so if a variable within the test may be null or undefined, you'l need to check that before accessing the variable in a way that would generate an error.

<Switch />

<Switch test={ condition }>
    <Case value="first">
        <span>If condition matches 'first'</span>
    </Case>
    <Case value="second">
        <span>If condition matches 'second'</span>
    </Case>
</Switch>

Component | Prop | Type | Notes --------- | ---- | ---- | ----- <Switch /> | test | any | The expression to check each case against. <Case /> | value | any | The value to compare against test.

The first matching case is rendered. If multiple cases match, only the first is rendered and and error is reported to the console.

<ForEach />

<ForEach items={ data }
         component={ DataView }
         as="item"
         spread
         keyGen={(item, index) => index}
         rest="wahtever I want" />                  

Prop | Type | Notes ---- | ---- | ----- items | any[] | Array of items to pass to the child components component | React component | The component that will be used to render each item in the items array. as | string | Optional. Specifies the name of the prop used to pass item to the rendered component. Default is item. spread | Boolean | Optional. When specified, instead of the item being passed as a single prop to the rendered component, each entry within the item is passed as a separate prop, similar to <Component {...item} />. Note as and spread are mutually exclusive. keyGen | string or function | Optional. Control over the key for each created child. If a string is passed, then it is assumed to be a property of each item. If a function is passed, it is called for each item with the item and index as arguments and is expected to return a uniue key. rest | any | Any other props provided to <ForEach /> are passed through to each component instances as-is.

Examples

See the unit tests under tests folder for many usage examples.

License

MIT License