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-if-vz

v2.1.0

Published

React declarative conditional rendering components (Ifz, When, Switch/Case) with support for nested conditions, dynamic children, and styling.

Readme

✨ react-if-vz


NPM JavaScript Style Guide Downloads


🌟 Live Demo

👉 Codesandbox


Description

A set of React components for declarative and readable conditional rendering, including:

  • Ifz / If / ElseIf / Else – for nested boolean conditions
  • When / WhenAll / WhenAny / WhenNot – for single-line conditional rendering
  • Switch / Case / Default – for discrete value matching
  • Supports dynamic children, debug logging, and custom class/style

Installation

install via npm:

npm i react-if-vz

Usage

import { Ifz, If, Else, ElseIf, When, Case, Switch, Default } from 'react-if-vz';

const [role, setRole] = useState('admin');

// support function
const isAdmin = () => {
  return role === 'admin';
}

//******************************** */
<Ifz>
  <Ifz.If condition={() => isAdmin()} debug="Admin check">
    <p>Welcome Admin</p>
  </Ifz.If>
  <Ifz.ElseIf condition={user.role === 'user'}>
    <p>Welcome User</p>
  </Ifz.ElseIf>
  <Ifz.Else>
    <p>Welcome Guest</p>
  </Ifz.Else>
</Ifz>

//******************************** */
// advance
<Ifz>
  <If condition={x => x > 10} args={[5]} debug="x > 10">
    {(x: number) => <div>Value {x} is big</div>}
  </If>

  <ElseIfz>
    <If condition={y => y < 5} args={[3]} debug="y < 5">
      <div>Nested check: y < 5</div>
    </If>
    <Else>
      {(args: unknown[]) => {
        const y = args[0] as number;
        return <div>Nested fallback: y = {y}</div>;
      }}
    </Else>
  </ElseIfz>

  <Else>
    {(args: unknown[]) => <div>Fallback content, args: {JSON.stringify(args)}</div>}
  </Else>
</Ifz>

//******************************** */
// Single => should use this instead of <If />
<When condition={isLoggedIn()}>
  <p>Welcome back!</p>
</When>

<WhenAll conditions={[isAdmin(), hasPermission()]}>
  <p>Admin panel</p>
</WhenAll>

<WhenAny conditions={[isAdmin(), isManager()]}>
  <p>Dashboard access</p>
</WhenAny>

<WhenNot condition={isGuest()}>
  <p>Non-guest content</p>
</WhenNot>

//******************************** */
<Switch value={user.role}>
  <Case value="admin">
    <p>Welcome Admin</p>
  </Case>
  <Case value="user">
    <p>Welcome Staff</p>
  </Case>
  <Default>
    <p>Welcome Guest</p>
  </Default>
</Switch>

//******************************** */
const [results, setResults] = useState(1);
<Switch>
  <Case value={() => results === 1}>
    <p>Welcome Admin</p>
  </Case>
  <Case value={() => results === 2}>
    <p>Welcome Staff</p>
  </Case>
  <Default>
    <p>Welcome Guest</p>
  </Default>
</Switch>

🔹 Props Summary

| Component | Props | Description | | --------------- | -------------------------------------------------------------- | ------------------------------- | | If / ElseIf | condition, children, args, className, style, debug | Conditional block | | Else | children (JSX or function), args, className, style | Fallback block | | Ifz | children | Wrapper for nested conditionals | | When | condition, children, args | Simple conditional | | WhenAll | conditions, children | Render if all true | | WhenAny | conditions, children | Render if any true | | WhenNot | condition, children | Render if false | | Switch | value, children, args | Discrete value switch | | Case | value, children, args, className, style, debug | Case block | | Default | children, args, className, style | Default block |


🔹 Advantages

  • Readable nested conditions instead of deeply nested ternary operators
  • Dynamic children support with function syntax
  • Debugging: know which conditional branch is rendered
  • Reusable args: pass values to multiple children / conditions
  • Styling: className / style per block

License

MIT