react-state-inspector-devtools 0.1.0 → 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.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +410 -0
  3. package/package.json +3 -2
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
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 ADDED
@@ -0,0 +1,410 @@
1
+ # react-state-inspector-devtools
2
+
3
+ A lightweight, runtime state inspector for React.
4
+ **Inspect and edit component state live — directly from your app.**
5
+
6
+ [![npm version](https://img.shields.io/npm/v/react-state-inspector-devtools.svg)](https://www.npmjs.com/package/react-state-inspector-devtools)
7
+ [![license](https://img.shields.io/npm/l/react-state-inspector-devtools.svg)](https://github.com/yourusername/react-state-inspector-devtools/blob/main/LICENSE)
8
+
9
+ ---
10
+
11
+ ## ✨ What is this?
12
+
13
+ `react-state-inspector-devtools` is a **dev-only** React tool that lets you:
14
+
15
+ - 👀 See which components are currently mounted
16
+ - 🔍 Inspect their internal state (`useState`)
17
+ - ✏️ Edit state values live from a floating UI panel
18
+ - ⚡ Observe UI updates instantly
19
+
20
+ **No browser extensions.**
21
+ **No React DevTools dependency.**
22
+ **Just drop it into your app.**
23
+
24
+ ---
25
+
26
+ ## 🧠 Why?
27
+
28
+ React DevTools are great — but sometimes you want:
29
+
30
+ - 🖥️ State inspection **inside the app**
31
+ - 🧪 A tool that works in **embedded environments**, previews, sandboxes
32
+ - 🎨 A way to poke state values quickly while **designing UI**
33
+ - ⚙️ **Zero setup**, zero configuration
34
+
35
+ > This tool is optimized for **developer experience**, not production analytics.
36
+
37
+ ---
38
+
39
+ ## 📦 Installation
40
+
41
+ ```bash
42
+ npm install react-state-inspector-devtools
43
+ ```
44
+
45
+ or
46
+
47
+ ```bash
48
+ pnpm add react-state-inspector-devtools
49
+ ```
50
+
51
+ or
52
+
53
+ ```bash
54
+ yarn add react-state-inspector-devtools
55
+ ```
56
+
57
+ ---
58
+
59
+ ## 🚀 Quick Start
60
+
61
+ ### 1️⃣ Wrap your app with the provider (dev-only)
62
+
63
+ ```tsx
64
+ import {
65
+ StateInspectorProvider,
66
+ StateInspectorUI,
67
+ } from "react-state-inspector-devtools";
68
+
69
+ export function AppRoot() {
70
+ return (
71
+ <StateInspectorProvider enabled={import.meta.env.DEV}>
72
+ <App />
73
+ {import.meta.env.DEV && <StateInspectorUI />}
74
+ </StateInspectorProvider>
75
+ );
76
+ }
77
+ ```
78
+
79
+ > ⚠️ **Important:**
80
+ > This tool is intended for **development only**.
81
+ > Always gate it behind `DEV` / `NODE_ENV !== "production"`.
82
+
83
+ ### 2️⃣ Opt-in to state inspection
84
+
85
+ Replace `useState` with `useInspectableState`:
86
+
87
+ ```tsx
88
+ import {
89
+ useInspectorComponent,
90
+ useInspectableState,
91
+ } from "react-state-inspector-devtools";
92
+
93
+ export function CounterCard() {
94
+ const inspector = useInspectorComponent("CounterCard");
95
+
96
+ const [count, setCount] = useInspectableState(
97
+ inspector,
98
+ "count",
99
+ 0,
100
+ { type: "number", min: 0, max: 999, step: 1 }
101
+ );
102
+
103
+ return (
104
+ <div>
105
+ <button onClick={() => setCount((c) => c - 1)}>-</button>
106
+ <span>{count}</span>
107
+ <button onClick={() => setCount((c) => c + 1)}>+</button>
108
+ </div>
109
+ );
110
+ }
111
+ ```
112
+
113
+ **That's it.**
114
+ The component and its state will appear in the inspector UI.
115
+
116
+ ---
117
+
118
+ ## 🪟 The Inspector UI
119
+
120
+ - Appears as a **floating button** in the bottom-right corner
121
+ - Opens a panel with:
122
+ - **Left:** Mounted components list
123
+ - **Right:** Editable state values
124
+ - State changes update the UI **immediately**
125
+
126
+ ### Supported Editors
127
+
128
+ | Type | Editor |
129
+ |------|--------|
130
+ | `boolean` | ✅ Checkbox |
131
+ | `number` | ✅ Number input (min / max / step) |
132
+ | `text` | ✅ Text input (with placeholder) |
133
+ | `select` | ✅ Dropdown |
134
+ | `json` | ✅ JSON editor |
135
+
136
+ ---
137
+
138
+ ## 🧩 API Reference
139
+
140
+ ### `StateInspectorProvider`
141
+
142
+ Wraps your app and controls whether the inspector is active.
143
+
144
+ ```tsx
145
+ <StateInspectorProvider enabled={boolean}>
146
+ {children}
147
+ </StateInspectorProvider>
148
+ ```
149
+
150
+ | Prop | Type | Description |
151
+ |------|------|-------------|
152
+ | `enabled` | `boolean` | Controls whether the inspector is active |
153
+ | `children` | `ReactNode` | Your application |
154
+
155
+ ---
156
+
157
+ ### `StateInspectorUI`
158
+
159
+ Renders the floating inspector overlay.
160
+
161
+ ```tsx
162
+ <StateInspectorUI />
163
+ ```
164
+
165
+ ---
166
+
167
+ ### `useInspectorComponent(label?: string)`
168
+
169
+ Registers a component instance with the inspector.
170
+
171
+ ```tsx
172
+ const inspector = useInspectorComponent("ProfileForm");
173
+ ```
174
+
175
+ - Creates a **stable component identity**
176
+ - Must be called **once per component**
177
+ - The `label` appears in the component list
178
+
179
+ ---
180
+
181
+ ### `useInspectableState<T>(inspector, key, initialValue, meta?)`
182
+
183
+ Drop-in replacement for `useState` that registers state with the inspector.
184
+
185
+ ```tsx
186
+ const [value, setValue] = useInspectableState(
187
+ inspector,
188
+ key,
189
+ initialValue,
190
+ meta?
191
+ );
192
+ ```
193
+
194
+ | Parameter | Type | Description |
195
+ |-----------|------|-------------|
196
+ | `inspector` | `InspectorComponentRef` | Returned from `useInspectorComponent` |
197
+ | `key` | `string` | State name shown in the UI |
198
+ | `initialValue` | `T` | Initial state value (same as `useState`) |
199
+ | `meta` | `InspectableMeta` | Optional UI hints for the editor |
200
+
201
+ ---
202
+
203
+ ## 📝 Meta Options
204
+
205
+ The `meta` parameter controls how the state is rendered in the inspector UI:
206
+
207
+ ### Boolean
208
+
209
+ ```tsx
210
+ { type: "boolean" }
211
+ ```
212
+
213
+ ### Number
214
+
215
+ ```tsx
216
+ { type: "number", min: 0, max: 100, step: 5 }
217
+ ```
218
+
219
+ ### Text
220
+
221
+ ```tsx
222
+ { type: "text", placeholder: "Enter name..." }
223
+ ```
224
+
225
+ ### Select (Dropdown)
226
+
227
+ ```tsx
228
+ {
229
+ type: "select",
230
+ options: ["small", "medium", "large"],
231
+ }
232
+
233
+ // Or with labels
234
+ {
235
+ type: "select",
236
+ options: [
237
+ { label: "Small", value: "sm" },
238
+ { label: "Medium", value: "md" },
239
+ { label: "Large", value: "lg" },
240
+ ],
241
+ }
242
+ ```
243
+
244
+ ### JSON
245
+
246
+ ```tsx
247
+ { type: "json" }
248
+ ```
249
+
250
+ > 💡 **Tip:** If you don't provide `meta`, the type is **automatically inferred** from the initial value.
251
+
252
+ ---
253
+
254
+ ## 🧪 Examples
255
+
256
+ ### Boolean Flags
257
+
258
+ ```tsx
259
+ export function FlagsPanel() {
260
+ const inspector = useInspectorComponent("FlagsPanel");
261
+
262
+ const [isAdmin, setIsAdmin] = useInspectableState(
263
+ inspector,
264
+ "isAdmin",
265
+ false,
266
+ { type: "boolean" }
267
+ );
268
+
269
+ const [betaUser, setBetaUser] = useInspectableState(
270
+ inspector,
271
+ "betaUser",
272
+ true,
273
+ { type: "boolean" }
274
+ );
275
+
276
+ return (
277
+ <div>
278
+ <label>
279
+ <input
280
+ type="checkbox"
281
+ checked={isAdmin}
282
+ onChange={(e) => setIsAdmin(e.target.checked)}
283
+ />
284
+ Is Admin
285
+ </label>
286
+ <label>
287
+ <input
288
+ type="checkbox"
289
+ checked={betaUser}
290
+ onChange={(e) => setBetaUser(e.target.checked)}
291
+ />
292
+ Beta User
293
+ </label>
294
+ </div>
295
+ );
296
+ }
297
+ ```
298
+
299
+ ### Select Dropdown
300
+
301
+ ```tsx
302
+ export function VariantPicker() {
303
+ const inspector = useInspectorComponent("VariantPicker");
304
+
305
+ const [variant, setVariant] = useInspectableState(
306
+ inspector,
307
+ "variant",
308
+ "M",
309
+ {
310
+ type: "select",
311
+ options: ["S", "M", "L", "XL"],
312
+ }
313
+ );
314
+
315
+ return (
316
+ <select value={variant} onChange={(e) => setVariant(e.target.value)}>
317
+ {["S", "M", "L", "XL"].map((v) => (
318
+ <option key={v} value={v}>{v}</option>
319
+ ))}
320
+ </select>
321
+ );
322
+ }
323
+ ```
324
+
325
+ ### Text Inputs
326
+
327
+ ```tsx
328
+ export function ProfileForm() {
329
+ const inspector = useInspectorComponent("ProfileForm");
330
+
331
+ const [name, setName] = useInspectableState(
332
+ inspector,
333
+ "name",
334
+ "",
335
+ { type: "text", placeholder: "Name" }
336
+ );
337
+
338
+ const [email, setEmail] = useInspectableState(
339
+ inspector,
340
+ "email",
341
+ "",
342
+ { type: "text", placeholder: "Email" }
343
+ );
344
+
345
+ return (
346
+ <div>
347
+ <input
348
+ value={name}
349
+ onChange={(e) => setName(e.target.value)}
350
+ placeholder="Name"
351
+ />
352
+ <input
353
+ value={email}
354
+ onChange={(e) => setEmail(e.target.value)}
355
+ placeholder="Email"
356
+ />
357
+ </div>
358
+ );
359
+ }
360
+ ```
361
+
362
+ ---
363
+
364
+ ## 🔒 Production Safety
365
+
366
+ - ✅ The inspector does **nothing** when `enabled={false}`
367
+ - ✅ No side effects, no global patches
368
+ - ✅ No state is tracked unless you **opt in**
369
+
370
+ > ⚠️ Still, **do not ship it enabled in production.**
371
+
372
+ ---
373
+
374
+ ## 🛠️ Use Cases
375
+
376
+ - 🎨 UI development & tweaking
377
+ - 📐 Design system work
378
+ - 📚 Component libraries
379
+ - 🖼️ Embedded previews
380
+ - 🔧 Internal tools
381
+ - 🎤 Demos & presentations
382
+
383
+ ---
384
+
385
+ ## 🧩 Inspired by
386
+
387
+ - [React DevTools](https://react.dev/learn/react-developer-tools)
388
+ - [Redux DevTools](https://github.com/reduxjs/redux-devtools)
389
+ - In-app debug overlays
390
+
391
+ …but intentionally **simpler** and **runtime-focused**.
392
+
393
+ ---
394
+
395
+ ## 📄 License
396
+
397
+ MIT
398
+
399
+ ---
400
+
401
+ ## ⭐ Feedback
402
+
403
+ This is a V1 devtool built for real-world usage.
404
+ Ideas, issues, and PRs are welcome!
405
+
406
+ ---
407
+
408
+ ## 🔗 Links
409
+
410
+ - [npm](https://www.npmjs.com/package/react-state-inspector-devtools)
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "react-state-inspector-devtools",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
+ "license": "MIT",
4
5
  "publishConfig": {
5
6
  "access": "public"
6
7
  },
@@ -29,4 +30,4 @@
29
30
  "lint": "eslint .",
30
31
  "format": "prettier . --check"
31
32
  }
32
- }
33
+ }