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 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-jsx-control

v1.0.7

Published

React JSX utility components for clean and efficient conditional and iterative rendering. Simplifies rendering logic with components like Ternary, Show, and SwitchCase.

Downloads

4

Readme

react-jsx-control

react-jsx-control is a utility library designed to simplify conditional rendering and looping in React applications. It provides a set of reusable components to make JSX cleaner and more readable.


Installation

npm install react-jsx-control
yarn add react-jsx-control
pnpm add react-jsx-control

Usage

1. Ternary

The Ternary component renders one of two ReactNodes (truthy or falsy) based on a condition.

import { Ternary } from 'react-jsx-control';

<Ternary
  when={true}
  truthy={<span>Truthy</span>}
  falsy={<span>Falsy</span>}
/>

2. SwitchCase

The SwitchCase component renders a specific child based on a match value.

import { SwitchCase } from 'react-jsx-control';

<SwitchCase
  match="a"
  caseBy={{
    a: <div>Case A</div>,
    b: <div>Case B</div>,
  }}
  fallback={<div>Default case</div>}
/>

3. Switch

The Switch component renders the first child whose when prop evaluates to true.

import { Switch, Match } from 'react-jsx-control';

<Switch>
  <Match when={false}>
    <div>Not rendered</div>
  </Match>
  <Match when={true}>
    <div>Rendered</div>
  </Match>
</Switch>

4. Show

The Show component renders its children when the condition is true. Otherwise, it renders the fallback content.

import { Show } from 'react-jsx-control';

<Show when={true} fallback={<div>Fallback</div>}>
  <div>Content to show</div>
</Show>;

5. For

The For component loops through an array and renders ReactNodes for each item.

import { For } from 'react-jsx-control';

const items = [
  { name: 'Item 1', value: 10 },
  { name: 'Item 2', value: 20 },
];

<For
  each={items}
  fallback={<div>No items available</div>}
>
  {({ name, value }, index) => (
    <div>
      <h1>{index + 1}. {name}</h1>
      <h2>{value}</h2>
    </div>
  )}
</For>;

Key Features

  • Ternary: Renders one of two ReactNodes based on a condition.
  • SwitchCase: Renders based on a specific value.
  • Switch: Renders the first matching child based on the when condition.
  • Show: Renders content or fallback based on a condition.
  • For: Loops through an array and renders elements.

Benefits

  • Improved readability of JSX code.
  • Simplifies complex conditional rendering.
  • Enhances React’s default conditional and iterative rendering patterns.

Contributing

Contributions and bug reports are always welcome! Feel free to visit the GitHub repository to get involved.

License

MIT License.

This is a fully markdown-ready file for your README. You can copy-paste this into your README.md without any modifications. 🚀