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-render-utils

v1.3.0

Published

![npm_version](https://img.shields.io/npm/v/react-render-utils) ![license](https://img.shields.io/npm/l/react-render-utils)

Readme

react-render-utils

npm_version license

A lightweight utility library to simplify conditional rendering in React using JSX. It provides intuitive components like <When>, <Switch>, and <Range> for common conditional rendering scenarios.


Table of Contents


Installation

Install the package via npm or yarn:

npm

npm install react-render-utils

yarn

yarn add react-render-utils

Components

When

The <When> component is ideal for simple conditional rendering like if-then-else.

Authentication example

<When value={isLoggedIn} then={<Dashboard />} otherwise={<LoginPage />} />

Inline content example

<When
  value={isLoggedIn}
  then={<>You are logged in</>}
  otherwise={<>Please log in</>}
/>

Switch

The <Switch> component helps render one of many possible options based on a value.

User role permissions example

<Switch
  value={userRole}
  cases={{
    admin: <AdminDashboard />,
    user: <UserDashboard />,
    Default: <GuestDashboard />, // Fallback
  }}
/>

UI section navigation example

<Switch
  value={currentAction}
  cases={{
    profile: <ProfileForm />,
    password: <PasswordForm />,
    notifications: <NotificationSettingsForm />,
    Default: <UserDashboard />,
  }}
/>

Range

The <Range> component simplifies range-based conditional rendering.

Score grading example

<Range
  value={studentScore}
  ranges={{
    "0-50": <div>Grade: F - Needs significant improvement.</div>,
    "51-60": <div>Grade: D - Passing.</div>,
    "61-70": <div>Grade: C - Satisfactory work.</div>,
    "71-85": <div>Grade: B - Good job!</div>,
    "86-100": <div>Grade: A - Excellent performance!</div>,
    Default: <div>Invalid score. Please contact admin.</div>,
  }}
/>

Loyalty tiers example

<Range
  value={loyaltyPoints}
  ranges={{
    "0-100": (
      <div>You're a Bronze member. Earn more points for bigger rewards!</div>
    ),
    "101-500": <div>You're a Silver member. Keep going for Gold status!</div>,
    "501-1000": (
      <div>You're a Gold member. Enjoy exclusive perks and discounts!</div>
    ),
    "1001-5000": (
      <div>You're a Platinum member. You're our most valued customer!</div>
    ),
    Default: <div>Invalid points. Please contact support for assistance.</div>,
  }}
/>

Functions

pluralise

Returns the singular or plural form of a word based on the count.

pluralise basic usage

// Returns singular or plural form based on count
pluralise(1, "apple", "apples"); // Returns: "apple"
pluralise(2, "apple", "apples"); // Returns: "apples"
pluralise(0, "apple", "apples"); // Returns: "apples"

pluraliseWithCount

Formats a count with the appropriate singular or plural form of a word.

pluraliseWithCount basic usage

// With default plural (singular + 's')
pluraliseWithCount(1, "apple"); // Returns: "1 apple"
pluraliseWithCount(2, "apple"); // Returns: "2 apples"
pluraliseWithCount(0, "apple"); // Returns: "0 apples"

Custom zero text

// Special text for zero count
pluraliseWithCount(0, "apple", "No apples"); // Returns: "No apples"

Custom plural form

// For irregular plurals
pluraliseWithCount(1, "child", null, "children"); // Returns: "1 child"
pluraliseWithCount(2, "child", null, "children"); // Returns: "2 children"

Hiding the count

// Just show the word without the number
pluraliseWithCount(2, "apple", null, "apples", true); // Returns: "apples"

Real-world examples

// In a component - showing item count
const items = ["item1", "item2", "item3", "item4", "item5"];
return (
  <div>You have {pluraliseWithCount(items.length, "item")} in your cart.</div>
);
// Renders: "You have 5 items in your cart"

// Empty state with zero count
const emptyCart = [];
return (
  <div>
    You have {pluraliseWithCount(emptyCart.length, "item")} in your cart.
  </div>
);
// Renders: "You have 0 items in your cart"

// Custom message for empty state
const messages = [];
return (
  <div>{pluraliseWithCount(messages.length, "message", "No new messages")}</div>
);
// Renders: "No new messages"

// Progress tracking with multiple counts
const completedTasks = ["task1", "task2"];
const totalTasks = 5;
return (
  <div>
    {pluraliseWithCount(completedTasks.length, "task")} completed,
    {pluraliseWithCount(totalTasks - completedTasks.length, "task")} remaining
  </div>
);
// Renders: "2 tasks completed, 3 tasks remaining"

License

MIT