components-switch
v1.0.0
Published
A lightweight React utility component library featuring Switch and Match for conditional rendering, inspired by SolidJS. Simplifies readable and declarative conditional logic in JSX.
Maintainers
Readme
🔀 components-switch
A lightweight React utility component library featuring
SwitchandMatchfor elegant conditional rendering—inspired by SolidJS, made for React.
✨ Features
- 🧠 Declarative conditional rendering
- 💡 Inspired by SolidJS's
Switch/Matchlogic - 🔩 Tiny footprint & zero dependencies
- ⚛️ Fully typed and compatible with React 17/18+
📦 Installation
npm install components-switchOr with yarn:
yarn add react-switch-match🧱 Usage
import { Switch, Match } from 'react-switch-match';
function Dashboard() {
return (
<Switch fallback={<p>If nothing is true, show this</p>}>
<Match when={shouldShowA}>
<Table />
</Match>
<Match when={shouldShowB() === true}>
<Analytics />
</Match>
<Match when={true}>
<SomethingElse />
</Match>
</Switch>
);
}import { Switch, Match } from 'react-switch-match';
function Greeting({ isLoggedIn }: { isLoggedIn: boolean }) {
return (
<Switch fallback={<p>Please log in.</p>}>
<Match when={isLoggedIn}>
<p>Welcome back!</p>
</Match>
</Switch>
);
}