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

reloc

v2.0.9

Published

React logic (control statements) components

Readme

Reloc – React Logic Components

npm License Contact

Reloc provides logic control components for React JSX, including:

  • <If> – simple conditional rendering
  • <Switch>, <Case>, <Default> – complex conditional logic
  • <For> – iteration over collections

Installation

npm

npm i reloc

yarn

yarn add reloc

API

1. Simple Conditional – <If>

Props

| Name | Type | Required | Description | | -------------------- | --------------------------- | -------- | --------------------- | | is | Boolean | ✔ | Condition to evaluate | | then or children | ReactNode | Function | null | ✖ | Content to render |

Examples

Recommended usage (with function):

import { If } from 'reloc';

<If is={obj} then={() => (
  <span>It is done</span>
)} />

Alternative syntax:

<If is={status === DONE}>
  {() => (
    <span>It is done</span>
  )}
</If>

⚠️ Unsafe syntax (not recommended):

<If is={status === DONE}>
  <span>It is done</span>
</If>

2. Complex Conditionals – Switch / Case

<Switch>

Only the first matching case will be rendered.

| Prop | Type | Required | Default | Description | | -------- |-------------------------| -------- | ------- | --------------------------------------------------- | | match | Boolean, Number, String | ✖ | true | Value to compare against cases | | strict | Boolean | ✖ | true | When enabled, comparison checks both value and type |


<Case>

| Prop | Type | Required | | -------------------- | --------------------------- | -------- | | is | Boolean | ✔ | | then or children | ReactNode | Function | null | ✖ |


<Default>

| Prop | Type | Required | | -------------------- | --------------------------- | -------- | | then or children | ReactNode | Function | null | ✖ |


Example 1: Conditional logic

import { Switch, Case, Default } from 'reloc';

<Switch>
  <Case is={status === DOING} then={() => (
      <span>DOING</span>
  )} />
  <Case is={status === DONE} then={() => (
      <span>DONE</span>
  )} />
  <Default then={() => (
      <span>OTHER</span>
  )} />
</Switch>

Alternative syntax:

<Switch>
  <Case is={status === DOING}>
    {() => (
        <span>DOING</span>
    )}
  </Case>
  <Case is={status === DONE}>
    {() => (
        <span>DONE</span>
    )}
  </Case>
  <Default>
    {() => (
        <span>OTHER</span>
    )}
  </Default>
</Switch>

Example 2: Switch mode

<Switch match={status}>
  <Case is={DOING} then={() => (
      <span>DOING</span>
  )} />
  <Case is={DONE} then={() => (
      <span>DONE</span>
  )} />
  <Default then={() => (
      <span>OTHER</span>
  )} />
</Switch>

Example 3: Switch mode with strict={false}

<Switch match={1} strict={false}>
  <Case is={'1'} then={() => (
      <span>Passed</span>
  )} />
  <Case is={'2'} then={() => (
      <span>Not passed</span>
  )} />
  <Default then={() => (
      <span>Not passed</span>
  )} />
</Switch>

⚠️ Unsafe syntax (not recommended):

<Switch match={status}>
    <Case is={'doing'}>
        <span>Passed</span>
    </Case>
    <Case is={'done'}>
        <span>Not Passed</span>
    </Case>
    <Default>
        <span>Not passed</span>
    </Default>
</Switch>

3. Loop – <For>

Supported data types:

  • Array
  • Set
  • Map
  • Object

Props

| Name | Type | Required | Description | | ---------- |-----------------------------------| -------- | --------------------- | | items | Array, Set, Map, Object | ✔ | Collection to iterate | | children | (item, key, index) => ReactNode | ✔ | Render function |

For Array and Set, key is the same as index.

Example

import { For } from 'reloc';

<For items={items}>
  {(item, key, index) => (
    <span key={key}>
      {index}: {item.name}
    </span>
  )}
</For>

Important: Deferring Evaluation of Children

JavaScript uses eager evaluation, meaning JSX expressions are executed even when conditions are false.

Incorrect ❌

<If is={obj}>
  <span>{obj.attr}</span>
</If>

This will throw an error if obj is undefined.

Correct ✅


<If is={obj} then={() => (
    <span>{obj.attr}</span>
)} />

Or:

<If is={obj}>
    {() => (
        <span>{obj.attr}</span>
    )}
</If>

👉 Recommendation: Always use arrow functions for children in:

  • <If>
  • <Case>
  • <Default>
  • <For>

For more discussion, see the React team issue: https://github.com/reactjs/react-future/issues/35


Alternative Solutions

Reloc prioritizes long-term compatibility with React, though the syntax may feel verbose in some cases.

If you prefer JSX syntax closer to native control statements, consider:

Limitations of these approaches:

  • ❌ Depend on specific transpilers (babel, tsx)
  • ❌ Limited compatibility with modern bundlers (Vite, esbuild, microbundle)
  • ❌ Poor IDE syntax highlighting
  • ❌ Potential maintenance issues when upgrading transpilers

👉 A React-component-based approach like Reloc is generally safer and more future-proof.