@storix-js/react 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.
package/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # @storix-js/react
2
+
3
+ React adapter for Storix using `useSyncExternalStore`.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @storix-js/core @storix-js/react react
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```tsx
14
+ import { useStore } from '@storix-js/react';
15
+ import { useCounterStore } from './store';
16
+
17
+ export function Counter() {
18
+ const counter = useStore(useCounterStore);
19
+ return <button onClick={() => counter.increment()}>{counter.count}</button>;
20
+ }
21
+ ```
22
+
23
+ This adapter subscribes React components to Storix updates with React 18-compatible semantics.
package/package.json CHANGED
@@ -1,10 +1,17 @@
1
1
  {
2
2
  "name": "@storix-js/react",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
8
+ "files": [
9
+ "dist",
10
+ "README.md"
11
+ ],
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
8
15
  "exports": {
9
16
  ".": {
10
17
  "types": "./dist/index.d.ts",
@@ -22,7 +29,7 @@
22
29
  "react": ">=18"
23
30
  },
24
31
  "dependencies": {
25
- "@storix-js/core": "workspace:*"
32
+ "@storix-js/core": "^0.1.1"
26
33
  },
27
34
  "devDependencies": {
28
35
  "@types/react": "^18.3.21",
package/src/index.ts DELETED
@@ -1,25 +0,0 @@
1
- import type { StoreInstance } from '@storix-js/core';
2
- import { useRef, useSyncExternalStore } from 'react';
3
-
4
- export function useStore<T extends (...args: never[]) => StoreInstance>(factory: T): ReturnType<T> {
5
- const storeRef = useRef<ReturnType<T> | null>(null);
6
- const versionRef = useRef(0);
7
-
8
- if (!storeRef.current) {
9
- storeRef.current = factory() as ReturnType<T>;
10
- }
11
-
12
- const store = storeRef.current as ReturnType<T>;
13
-
14
- useSyncExternalStore(
15
- (onStoreChange) =>
16
- store.$subscribe(() => {
17
- versionRef.current += 1;
18
- onStoreChange();
19
- }),
20
- () => versionRef.current,
21
- () => versionRef.current
22
- );
23
-
24
- return store;
25
- }
@@ -1,8 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "rootDir": "src",
5
- "outDir": "dist",
6
- "paths": {}
7
- }
8
- }
package/tsconfig.json DELETED
@@ -1,4 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "include": ["src"]
4
- }
package/vite.config.ts DELETED
@@ -1,15 +0,0 @@
1
- import { defineConfig } from 'vite';
2
-
3
- export default defineConfig({
4
- build: {
5
- lib: {
6
- entry: 'src/index.ts',
7
- name: 'StorixReact',
8
- fileName: 'index',
9
- formats: ['es', 'cjs']
10
- }
11
- },
12
- test: {
13
- environment: 'node'
14
- }
15
- });