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-if-then-else-switch

v1.0.4

Published

A React library for declarative conditional rendering using If/Else and Switch/Case components for cleaner JSX.

Readme

react-if-then-else-switch

npm version

License: MIT TypeScript

NPM Downloads


🚀 Declarative Conditional Rendering for React

react-if-then-else-switch is a lightweight and intuitive library that provides declarative components for handling conditional rendering in your React applications. Say goodbye to deeply nested ternary operators and complex && chains, and embrace cleaner, more readable JSX.


📚 Documentation & Demos

Explore live examples and detailed usage instructions in our comprehensive documentation:

👉 View Documentation & Live Demos Here 👈

✨ Features

  • <IfElse> Wrapper: A powerful wrapper component that orchestrates your conditional logic.

  • <If> Component: Renders content only if its condition prop is true.

  • <ElIf> Component: (Else If) Renders content if its condition is true AND all preceding If/ElIf conditions within the same <IfElse> block were false.

  • <Else> Component: Renders content if no preceding If or ElIf conditions within the same <IfElse> block were true.

  • <Switch> Component: A declarative container that evaluates a value prop against multiple <Case> conditions. Only the first matching <Case> (or the <Default>) will render.

  • <Case> Component: Renders content if its condition prop (or a specific value prop, depending on your implementation) matches the value prop of the parent <Switch> component.

  • <Default> Component: Renders content if no preceding <Case> components within the same <Switch> block had a matching condition. This acts as the fallback for a Switch statement.


📦 Installation

Install react-if-then-else-switch using npm or yarn:

npm install react-if-then-else-switch
# OR
yarn add react-if-then-else-switch

🤔 Why react-if-then-else-switch?

While React's native JSX conditionals (&&, ? :) are powerful, they can lead to:

  • Nested Ternary Hell: Deeply nested ? : can quickly become unreadable and hard to maintain.
  • Verbose && Chains: Multiple && operators for else if logic can be awkward and less explicit.
  • Lack of Structure: It can be hard to visually parse complex conditional blocks.

react-if-then-else-switch offers:

  • Improved Readability: Declarative components clearly indicate conditional blocks.
  • Structural Clarity: Your JSX visually reflects the if-else if-else flow.
  • Reduced Boilerplate: No need for manual wrapping of expressions for else conditions.

🤝 Contributing

We welcome contributions! Please see our CONTRIBUTING.md for guidelines on how to contribute to this project, report bugs, and suggest features.

📄 License

This project is licensed under the MIT License.