A React library for declarative conditional rendering using If/Else and Switch/Case components for cleaner JSX.
npm install react-if-then-else-switch



---
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.
---
Explore live examples and detailed usage instructions in our comprehensive documentation:
š View Documentation & Live Demos Here š
- Wrapper: A powerful wrapper component that orchestrates your conditional logic.
- Component: Renders content only if its condition prop is true.
- Component: (Else If) Renders content if its condition is true AND all preceding If/ElIf conditions within the same block were false.
- Component: Renders content if no preceding If or ElIf conditions within the same block were true.
- Component: A declarative container that evaluates a value prop against multiple conditions. Only the first matching (or the ) will render.
- Component: Renders content if its condition prop (or a specific value prop, depending on your implementation) matches the value prop of the parent component.
- Component: Renders content if no preceding components within the same block had a matching condition. This acts as the fallback for a Switch statement.
---
Install react-if-then-else-switch using npm or yarn:
``bash
npm install react-if-then-else-switchOR
yarn add react-if-then-else-switch
``
- 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.
- 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.
We welcome contributions! Please see our CONTRIBUTING.md for guidelines on how to contribute to this project, report bugs, and suggest features.
This project is licensed under the MIT License.