react-state-basis 0.1.1 → 0.1.2
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/README.md +41 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -138,6 +138,7 @@ export default function Root() {
|
|
|
138
138
|
### 2. Use Drop-in Replacement Imports
|
|
139
139
|
Replace your standard React hook imports with `react-state-basis`. This allows the engine to instrument your state updates without changing your component logic.
|
|
140
140
|
|
|
141
|
+
**Standard Named Imports (Recommended):**
|
|
141
142
|
```tsx
|
|
142
143
|
// ❌ Change this:
|
|
143
144
|
// import { useState, useEffect } from 'react';
|
|
@@ -150,7 +151,46 @@ function MyComponent() {
|
|
|
150
151
|
}
|
|
151
152
|
```
|
|
152
153
|
|
|
153
|
-
|
|
154
|
+
**Namespace Imports:**
|
|
155
|
+
Basis also supports namespace imports if you prefer to keep your hooks grouped:
|
|
156
|
+
```tsx
|
|
157
|
+
import * as Basis from 'react-state-basis';
|
|
158
|
+
|
|
159
|
+
function MyComponent() {
|
|
160
|
+
const [count, setCount] = Basis.useState(0); // Also tracked automatically
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### 3. The Babel plugin
|
|
165
|
+
The Babel plugin is optional but highly recommended. Without it, state variables will be tracked as anonymous_state, making it difficult to identify specific redundancies in large applications. You can also manually provide a label as the last argument to any hook if you prefer not to use Babel.
|
|
166
|
+
|
|
167
|
+
> If you choose not to use the Babel plugin, you can still get specific labels by passing a string as the last argument:
|
|
168
|
+
|
|
169
|
+
```tsx
|
|
170
|
+
const [count, setCount] = useState(0, "MyComponent -> count");
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
To get the most out of Basis, you should enable the Babel plugin. This automatically injects the **filename** and **variable name** into your hooks so you don't have to label them manually.
|
|
174
|
+
|
|
175
|
+
If you are using **Vite**, add the following to your `vite.config.ts`:
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
// vite.config.ts
|
|
179
|
+
import { defineConfig } from 'vite'
|
|
180
|
+
import react from '@vitejs/plugin-react'
|
|
181
|
+
|
|
182
|
+
export default defineConfig({
|
|
183
|
+
plugins: [
|
|
184
|
+
react({
|
|
185
|
+
babel: {
|
|
186
|
+
// Automatically labels useState, useMemo, etc.
|
|
187
|
+
// for richer diagnostics in the console.
|
|
188
|
+
plugins: [['react-state-basis/plugin']]
|
|
189
|
+
}
|
|
190
|
+
})
|
|
191
|
+
]
|
|
192
|
+
})
|
|
193
|
+
```
|
|
154
194
|
|
|
155
195
|
|
|
156
196
|
---
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-state-basis",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "A linear algebra-powered React architectural tool that detects redundant state and synchronization anti-patterns by modeling state transitions as vectors in a basis.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|