You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Braided** is a minimal, type-safe library for declarative system composition with dependency-aware lifecycle management. **Braided React** provides the bridge to use those systems seamlessly in React applications.
8
+
9
+
## What is Braided?
10
+
11
+
[**Braided**](https://github.com/RegiByte/braided) is a minimal (~300 lines), type-safe library for declarative system composition with dependency-aware lifecycle management. It lets you define stateful resources (databases, WebSockets, caches, etc.) with explicit dependencies, and handles starting/stopping them in the correct order.
12
+
13
+
Think of it as **dependency injection + lifecycle management** for JavaScript, inspired by Clojure's Integrant.
14
+
7
15
## Why Braided React?
8
16
9
-
Modern React apps often need to manage complex, long-lived resources that don't fit neatly into the react component lifecycle:
17
+
Modern React apps often need to manage complex, long-lived resources that don't fit neatly into the React component lifecycle:
-**Complex API Clients** (Authentication, Retries, Caching)
14
22
-**Game Loops & Simulations**
23
+
-**Background Tasks** (Sync, Polling, Timers)
15
24
16
25
Managing these inside `useEffect` often leads to "dependency hell," double-initialization in StrictMode, and race conditions.
17
26
18
-
**Braided React** solves this by letting you define your system *outside* React, and then bridging it *into* React as a fully-typed dependency injection layer.
27
+
**Braided React** solves this by letting you define your system _outside_ React using Braided, and then bridging it _into_ React as a fully-typed dependency injection layer. Your resources outlive React's mount/unmount cycles and you decide when/how to stop them.
19
28
20
29
## Features
21
30
@@ -31,157 +40,183 @@ Managing these inside `useEffect` often leads to "dependency hell," double-initi
31
40
npm install braided-react braided
32
41
```
33
42
34
-
Peer dependencies: `react >= 18.0.0` and `braided >= 0.0.4`
43
+
**Requirements:**
44
+
45
+
-`react >= 18.0.0` (peer dependency)
46
+
-`braided >= 0.0.4` (peer dependency)
47
+
48
+
**Note:** You need both libraries. [Braided](https://github.com/RegiByte/braided) defines your system, Braided React bridges it to React.
System starts on mount with loading states and async resources.
161
+
Simple example that demonstrates the core functionality of the library: your system running even when React is unmounted. It's up to you how to compose this powerful pattern into your app.
133
162
134
163
```bash
135
-
cd examples/lazy-start
164
+
cd examples/outliving-react
136
165
npm install && npm run dev
137
166
```
138
167
168
+
**Best for:** Music players, WebSocket apps, background sync, game engines, scheduled tasks, etc.
169
+
170
+
See [examples/README.md](./examples/README.md) for detailed comparison and learning path.
171
+
139
172
## Reactivity & State Management
140
173
141
-
**Important:**`braided-react` is a Dependency Injection (DI) library, **not** a state management library.
174
+
**Important:**`braided-react` is a Lifecycle management and Dependency Injection (DI) library, **not** a state management library.
142
175
143
-
When you call `useResource('counter')`, you get the *instance* of the counter. If properties on that instance change, your component **will not re-render** automatically.
176
+
When you call `useResource('counter')`, you get the _instance_ of the counter. If properties on that instance change, your component **will not re-render** automatically.
144
177
145
-
### Recommended Pattern: Zustand Integration
178
+
### Recommended Pattern: Zustand Integration or your preferred state management library
146
179
147
-
To make your UI reactive, we recommend using a state manager like [Zustand](https://github.com/pmndrs/zustand) alongside your Braided resources.
180
+
To make your UI reactive, we recommend using a state manager like [Zustand](https://github.com/pmndrs/zustand) alongside your system resources or as one of them if you'd like.
148
181
149
-
1.**Resource:** Holds the *business logic* and *connections* (e.g., WebSocket).
150
-
2.**Store:** Holds the *reactive state* (e.g., current messages).
182
+
1.**Resource:** Holds the _business logic_ and _connections_ (e.g., WebSocket).
183
+
2.**Store:** Holds the _reactive state_ (e.g., current messages).
151
184
3.**Component:** Subscribes to the store and calls methods on the resource.
Copy file name to clipboardExpand all lines: examples/README.md
+11-2Lines changed: 11 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,10 @@
1
1
# 🧶 Braided React Examples
2
2
3
-
Four complete examples demonstrating modern patterns for integrating Braided systems with React.
3
+
Four complete examples demonstrating modern patterns for integrating [Braided](https://github.com/RegiByte/braided) systems with React.
4
+
5
+
**What is Braided?** A minimal, type-safe library for declarative system composition with dependency-aware lifecycle management. Think dependency injection + lifecycle management for JavaScript.
6
+
7
+
**What is Braided React?** The bridge that lets you use Braided systems in React applications without giving up lifecycle control.
4
8
5
9
## Examples Overview
6
10
@@ -237,4 +241,9 @@ All examples follow these principles:
237
241
238
242
**Untangle your code. Compose your systems. Let React observe.** 🧶
0 commit comments