An open API service indexing awesome lists of open source software.

https://github.com/delpikye-v/react-loop

React wrapper loop. Simple and easy to use
https://github.com/delpikye-v/react-loop

loops react-for-each react-loop

Last synced: about 1 month ago
JSON representation

React wrapper loop. Simple and easy to use

Awesome Lists containing this project

README

          

# ✨ react-loop-z

[![NPM](https://img.shields.io/npm/v/react-loop-z.svg)](https://www.npmjs.com/package/react-loop-z) ![Downloads](https://img.shields.io/npm/dt/react-loop-z.svg)

LIVE EXAMPLE

---

**react-loop-z** is a lightweight, type-safe, declarative looping
toolkit for React.

It helps you replace `.map()` chains and manual iteration logic with
**clean, expressive JSX blocks**.

> Write loops like logic. Render JSX like structure.

---

## πŸ“– Why react-loop-z?

- Declarative JSX loops
- Strict TypeScript support
- Zero dependencies
- Tree-shakable
- Infinite loop protection (safe guards)
- SSR & StrictMode safe
- Tiny bundle size

---

## 🧠 Mental Model

- Pure function components
- No internal state machines
- No proxies or runtime magic
- Strict generic typing
- Guard-based loop safety

> Each loop is an independent, tree-shakable unit.
> Import only what you use.

---

## πŸ“¦ Installation

``` bash
npm install react-loop-z
```

---

## πŸš€ Usage

#### πŸ” For (Array iteration)

``` tsx
import { For } from "react-loop-z";

{(item, index) => (
Hello, {item}
)}

```

Type-safe example:

``` tsx
type User = { id: number; name: string };

of={users}>
{(user) =>

{user.name}
}

```

---

#### πŸ”’ Range / Numeric Loop

``` tsx
import { RangeLoop } from "react-loop-z";

{(i) =>

{i}
}

```

---

#### πŸ”‚ While

``` tsx
import { While } from "react-loop-z";

let i = 0;

i++ < 3}
>
{(index) =>

Count {index}
}

```

---

#### πŸ”„ Do

``` tsx
import { Do } from "react-loop-z";

let i = 0;

i < 3}
>
{(index) => {
i++;
return

Count {index}
;
}}

```

---

#### πŸ—ΊοΈ MapLoop

``` tsx
import { MapLoop } from "react-loop-z";

{(value, key) => (


{key}: {value}

)}

```

---

#### 🧩 SetLoop

``` tsx
import { SetLoop } from "react-loop-z";

{(item) =>

{item}
}

```

---

#### πŸ—‚οΈ ObjectLoop

``` tsx
import { ObjectLoop } from "react-loop-z";

{(value, key) => (


{key}: {value}

)}

```

---

## πŸ›‘ Infinite Loop Protection

`While`, `Do`, and numeric loops include safety guards to prevent
runaway infinite loops in development.

Always ensure your condition eventually becomes false.

---

#### πŸ”₯ BreakableLoop

Declarative loop with early exit support (like `break` in JavaScript).

``` tsx

{(user, { breakLoop }) => {
if (!user.active) breakLoop()
return
}}

```

---

#### πŸ”Ž FilterLoop

Render conditionally without chaining `.filter().map()`.

``` tsx
p.inStock}>
{(product) => }

```

---

#### 🧱 ChunkLoop

Split an array into chunks (ideal for grid or row rendering).

``` tsx

{(chunk) => (


{chunk.map(post => )}

)}

```

---

#### βœ‚οΈ TakeLoop

Render only the first N elements (lightweight alternative to `slice`).

``` tsx

{(msg) => }

```

---

#### 🧬 UniqueLoop

Remove duplicates by key selector before rendering.

``` tsx
u.email}>
{(user) => }

```

---

#### πŸ“¦ FlatLoop

Flatten nested arrays before rendering.

``` tsx

{(comment) => }

```

---

#### ⏳ AsyncLoop

Supports async iterables, promises, or async generators with built-in
async handling.

``` tsx

{(user) => }

```

Or:

``` tsx

{(value) =>

{value}
}

```

---

## ⚑ Core Numeric Loops

#### RangeLoop

Declarative numeric range loop.

``` tsx

{(i) =>

{i}
}

```

---

#### TimesLoop

Render N times (simple repeat utility).

``` tsx

{(index) => }

```

---

## πŸ“Š Comparison

| Feature | react-loop-z | react-loops | react-for | Native `.map()` |
|-----------------------------|--------------|-------------|-----------|-----------------|
| Declarative JSX Blocks | βœ… | βœ… | βœ… | ❌ |
| Strong TypeScript Inference | βœ… | ⚠️ Partial | ⚠️ | ⚠️ Manual |
| Array Loop | βœ… | βœ… | βœ… | βœ… |
| Numeric / Range Loop | βœ… | ❌ | ⚠️ | ❌ |
| While / Do Loop | βœ… | ⚠️ | ⚠️ | ❌ |
| Map / Set / Object Support | βœ… | βœ… Iterable | ⚠️ | ⚠️ Manual |
| Break Control | βœ… | ❌ | ❌ | ❌ |
| Async Loop | βœ… | ❌ | ❌ | ❌ |
| Infinite Loop Protection | βœ… | ❌ | ❌ | ❌ |
| Zero Runtime Dependencies | βœ… | ❌ | ⚠️ | βœ… |
| Tree-Shakable | βœ… | ❌ | ❌ | βœ… |

> A declarative loop control system for React β€” not just array mapping.

---

## 🎯 Philosophy

- Keep rendering pure
- Keep iteration declarative
- Keep bundle tiny
- Keep logic readable

> Iteration belongs to structure, not utility chains.

---

## 🏁 Final Thought

react-loop-z is not trying to replace `.map()`.

It provides:

- Structure-driven iteration
- Declarative control flow
- Composable loop primitives

Think of it as: **Control flow components for React.**

---

## πŸ“„ License

MIT