react-state-flow 0.0.3 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 HoangSonDeveloper
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,41 +1,79 @@
1
1
  # react-state-flow
2
2
 
3
- Visualize your React component hierarchy and state flow in real-time.
3
+ Visualize React component state and re-render flow in real time.
4
4
 
5
- <!-- screenshot here -->
5
+ Parses your React codebase into an interactive graph, then overlays live render data from your running app — so you can see which components re-render, how often, and how state flows through the tree.
6
6
 
7
- ## Usage
7
+ ## How it works
8
+
9
+ 1. **Static analysis** — scans your source files and builds a component graph (components, contexts, parent-child relationships)
10
+ 2. **Runtime instrumentation** — hooks into React DevTools to capture render events without modifying your components
11
+ 3. **Live visualization** — renders an interactive graph in the browser, updated in real time as your app runs
8
12
 
9
- Run in any React project — no install required:
13
+ ## Installation
10
14
 
11
15
  ```bash
12
- npx react-state-flow ./src
16
+ npm install react-state-flow
13
17
  ```
14
18
 
15
- A browser window opens at `http://localhost:7272` showing an interactive graph of your components, their relationships, and context providers.
19
+ ## Usage
20
+
21
+ ### Step 1 — Add runtime instrumentation
16
22
 
17
- The graph updates automatically when you save files.
23
+ Import at the very top of your `main.tsx` (before React mounts):
18
24
 
19
- ## Runtime instrumentation (optional)
25
+ ```ts
26
+ import 'react-state-flow/runtime'
27
+ import { StrictMode } from 'react'
28
+ import { createRoot } from 'react-dom/client'
29
+ import App from './App'
30
+
31
+ createRoot(document.getElementById('root')!).render(
32
+ <StrictMode>
33
+ <App />
34
+ </StrictMode>
35
+ )
36
+ ```
20
37
 
21
- To see which components are re-rendering and how many times, add the runtime to your app:
38
+ The runtime is automatically disabled in production (`NODE_ENV=production` or Vite's `MODE=production`), so this import is safe to commit.
39
+
40
+ ### Step 2 — Run the CLI
22
41
 
23
42
  ```bash
24
- npm install @rsf/runtime
43
+ npx react-state-flow ./src
25
44
  ```
26
45
 
27
- ```ts
28
- // main.tsx — must be the very first import
29
- import '@rsf/runtime'
46
+ The browser opens automatically at `http://localhost:7272` with your component graph. Start your app and the graph updates live as components render.
47
+
48
+ ## CLI
49
+
50
+ ```bash
51
+ react-state-flow [directory]
30
52
  ```
31
53
 
32
- Components that re-render will be highlighted in the graph in real-time.
54
+ | Argument | Default | Description |
55
+ |---|---|---|
56
+ | `directory` | `.` | Path to your React source directory |
57
+
58
+ The CLI runs on port `7272`. Your app's Vite dev server can run on any other port.
59
+
60
+ ## What the graph shows
61
+
62
+ - **Component nodes** — each React function component, with its `useState`/`useReducer` state slots listed
63
+ - **Context nodes** — each `createContext` call
64
+ - **Parent-child edges** — JSX render relationships between components
65
+ - **Context provision edges** — which component renders a `Context.Provider`
66
+ - **Context subscription edges** — which components call `useContext`
67
+ - **Render counts** — live badge on each node showing how many times it has rendered
68
+ - **Render flash** — green highlight for 800ms after a component re-renders
69
+
70
+ The graph updates automatically when you save source files (no restart needed).
33
71
 
34
72
  ## Requirements
35
73
 
36
- - Node 18+
37
- - React 17 or 18
74
+ - Node.js 18+
75
+ - React 16.8+ (hooks required for DevTools hook support)
38
76
 
39
- ## How it works
77
+ ## License
40
78
 
41
- `react-state-flow` parses your source files statically using Babel to extract component relationships and context usage, then serves an interactive graph UI. The optional `@rsf/runtime` package hooks into React's internal fiber reconciler (the same mechanism used by React DevTools) to capture render events and stream them to the UI over WebSocket.
79
+ MIT
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}