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-jsx-flow

v0.9.0

Published

A collection of JSX flow control components

Readme

React JSX Flow

build npm size Quality Gate Status

A collection of React JSX flow control components. Highly insipred by SolidJS flow components

Introduction

This package provide some controllers which makes JSX flow control easier and more declarative. Memoization support is provided out of the box when possible, and, fallback is used when provided. They include <For>, <ForIf>, <Show>, Hide and <Switch>/<Match>

Install

This package requires some peer dependencies, which you need to install by yourself.

yarn add react-jsx-flow react react-dom

or

npm i react-jsx-flow react react-dom

For React Native users:

yarn add react-jsx-flow react react-native

or

npm i react-jsx-flow react react-native

Usage

The following are the available components

<For> and <ForMemo>

They are basically the same components except that ForMemo supports memoization using React.memo under the hood.

<For>

It accepts an array which will be mapped according to the provided mapping function and a JSX template. And an optional fallback when the array is empty, null or undefined.

import { For } from 'react-jsx-flow'

const Component = () => {
  const array = ['a', 'b', 'c']
  return (
    <For each={array} fallback={<>Loading...</>}>
      {(item, index) => <div key={index}>{item}</div>}
    </For>
  )
}

For the mapping function, the index can be omitted in case it is available from the object, for example:

import { For } from 'react-jsx-flow'

const Component = () => {
  const array = [
    { id: 1, title: 'Item 1' },
    { id: 2, title: 'Item 2' },
  ]
  return (
    <For each={array} fallback={<>Loading...</>}>
      {(item) => <div key={item.id}>{item.title}</div>}
    </For>
  )
}

<ForMemo>

Same as For, however, in order to benefit from memoization, you need to use useCallback so that the mapping function is not recreated each time with every re-render.

import { useCallback } from 'react'
import { ForMemo } from 'react-jsx-flow'

const Component = () => {
  const array = ['a', 'b', 'c']
  const mappingFunction = useCallback(
    (item, index) => <div key={index}>{item}</div>,
    []
  )

  return (
    <ForMemo each={array} fallback={<>Loading...</>}>
      {mappingFunction}
    </ForMemo>
  )
}

<ForIf> and <ForIfMemo>

Same as For but also support filtering. They are basically the same components except that ForIfMemo supports memoization using React.memo under the hood.

<ForIf>

It accepts an array which will be mapped according to the provided mapping function. A filter function should also provided. An optional fallback when the array is empty, null or undefined.

import { ForIf } from 'react-jsx-flow'

const Component = () => {
  const array = ['a', 'b', 'c']
  return (
    <ForIf
      each={array}
      when={(item) => item !== 'a'}
      fallback={<>Loading...</>}
    >
      {(item, index) => <div key={index}>{item}</div>}
    </ForIf>
  )
}

<ForIfMemo>

Same as ForIf, however, in order to benefit from memoization, you need to use useCallback so that the mapping function and the filter function are not recreated each time with every re-render.

import { useCallback } from 'react'
import { ForIfMemo } from 'react-jsx-flow'

const Component = () => {
  const array = ['a', 'b', 'c']
  const filterFunction = useCallback((item) => item !== 'a', [])
  const mappingFunction = useCallback(
    (item, index) => <div key={index}>{item}</div>,
    []
  )

  return (
    <ForIfMemo each={array} when={filterFunction} fallback={<>Loading...</>}>
      {mappingFunction}
    </ForIfMemo>
  )
}

<Show>

It accepts a condition which when true it will show the provided JSX. An optional fallback when the condition is false.

import { Show } from 'react-jsx-flow'

const Component = () => {
  const shouldShow = true

  return (
    <Show when={shouldShow} fallback={<>Loadding...</>}>
      <div>Desired Content</div>
    </Show>
  )
}

<Hide>

It accepts a condition which when true it will hide the provided JSX. An optional fallback when the condition is false.

import { Hide } from 'react-jsx-flow'

const Component = () => {
  const shouldHide = true

  return (
    <Hide when={shouldHide} fallback={<>Loadding...</>}>
      <div>Desired Content</div>
    </Hide>
  )
}

<Switch>/<Match>

They are used together to show or hide matches based on certain condition. When all conditions are false, a fallback provided in Switch can be used.

import { Switch, Match } from 'react-jsx-flow'

const Component = () => {
  return (
    <Switch fallback={<>Loading...</>}>
      <Match when={false}>
        <div>I'm currently hidden</div>
      </Match>
      <Match when={true}>I'm currently shown</Match>
    </Switch>
  )
}