what-react 0.1.0 → 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 +131 -0
- package/package.json +5 -5
package/README.md
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# what-react
|
|
2
|
+
|
|
3
|
+
React compatibility layer for [What Framework](https://whatfw.com). Use React ecosystem libraries with What's signal-based engine under the hood -- zero code changes required.
|
|
4
|
+
|
|
5
|
+
**90+ React libraries confirmed working**, including zustand, @tanstack/react-query, react-hook-form, framer-motion, @radix-ui, react-select, react-router, and many more.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install what-react what-core
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Setup
|
|
14
|
+
|
|
15
|
+
Add the Vite plugin -- one line is all you need:
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
// vite.config.js
|
|
19
|
+
import { defineConfig } from 'vite';
|
|
20
|
+
import { reactCompat } from 'what-react/vite';
|
|
21
|
+
|
|
22
|
+
export default defineConfig({
|
|
23
|
+
plugins: [reactCompat()],
|
|
24
|
+
});
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
The plugin handles everything automatically:
|
|
28
|
+
- Aliases `react` and `react-dom` imports to `what-react`
|
|
29
|
+
- Configures JSX to use the What runtime
|
|
30
|
+
- Auto-detects installed React packages and excludes them from pre-bundling
|
|
31
|
+
- Resolves `use-sync-external-store` shims
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
Install any React library and use it normally. No code changes needed.
|
|
36
|
+
|
|
37
|
+
```jsx
|
|
38
|
+
// zustand -- just works
|
|
39
|
+
import { create } from 'zustand';
|
|
40
|
+
|
|
41
|
+
const useStore = create((set) => ({
|
|
42
|
+
count: 0,
|
|
43
|
+
increment: () => set((s) => ({ count: s.count + 1 })),
|
|
44
|
+
}));
|
|
45
|
+
|
|
46
|
+
function Counter() {
|
|
47
|
+
const count = useStore((s) => s.count);
|
|
48
|
+
const increment = useStore((s) => s.increment);
|
|
49
|
+
return <button onClick={increment}>Count: {count}</button>;
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
```jsx
|
|
54
|
+
// @tanstack/react-query -- just works
|
|
55
|
+
import { QueryClient, QueryClientProvider, useQuery } from '@tanstack/react-query';
|
|
56
|
+
|
|
57
|
+
const queryClient = new QueryClient();
|
|
58
|
+
|
|
59
|
+
function App() {
|
|
60
|
+
return (
|
|
61
|
+
<QueryClientProvider client={queryClient}>
|
|
62
|
+
<Todos />
|
|
63
|
+
</QueryClientProvider>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function Todos() {
|
|
68
|
+
const { data } = useQuery({
|
|
69
|
+
queryKey: ['todos'],
|
|
70
|
+
queryFn: () => fetch('/api/todos').then(r => r.json()),
|
|
71
|
+
});
|
|
72
|
+
return <ul>{data?.map(t => <li key={t.id}>{t.title}</li>)}</ul>;
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## How It Works
|
|
77
|
+
|
|
78
|
+
`what-react` implements React's public API using What's signals and reconciler:
|
|
79
|
+
|
|
80
|
+
- `useState`, `useEffect`, `useMemo`, etc. map to What's hook system
|
|
81
|
+
- `createElement` maps to What's `h()` hyperscript
|
|
82
|
+
- Class components (`Component`, `PureComponent`) are wrapped as function components
|
|
83
|
+
- `createRoot` / `render` map to What's `mount()`
|
|
84
|
+
- `createPortal` creates portal vnodes handled by What's reconciler
|
|
85
|
+
- `forwardRef`, `cloneElement`, `Children`, `createContext` all implemented
|
|
86
|
+
|
|
87
|
+
The key insight: React libraries import `react` and call its hooks. By aliasing `react` to `what-react`, those hooks execute on What's signal engine instead. The library never knows the difference.
|
|
88
|
+
|
|
89
|
+
## What's Implemented
|
|
90
|
+
|
|
91
|
+
### React (index.js)
|
|
92
|
+
|
|
93
|
+
`useState`, `useEffect`, `useLayoutEffect`, `useInsertionEffect`, `useMemo`, `useCallback`, `useRef`, `useContext`, `useReducer`, `useImperativeHandle`, `useId`, `useDebugValue`, `useSyncExternalStore`, `useTransition`, `useDeferredValue`, `createElement`, `createContext`, `createRef`, `createFactory`, `forwardRef`, `cloneElement`, `isValidElement`, `Component`, `PureComponent`, `Fragment`, `Suspense`, `StrictMode`, `memo`, `lazy`, `Children`, `startTransition`
|
|
94
|
+
|
|
95
|
+
### ReactDOM (dom.js)
|
|
96
|
+
|
|
97
|
+
`createRoot`, `hydrateRoot`, `render`, `unmountComponentAtNode`, `createPortal`, `flushSync`, `findDOMNode`, `unstable_batchedUpdates`
|
|
98
|
+
|
|
99
|
+
### Vite Plugin (vite-plugin.js)
|
|
100
|
+
|
|
101
|
+
`reactCompat(options?)` -- configures all aliases and optimizeDeps automatically
|
|
102
|
+
|
|
103
|
+
## Plugin Options
|
|
104
|
+
|
|
105
|
+
```js
|
|
106
|
+
reactCompat({
|
|
107
|
+
exclude: ['my-custom-react-lib'], // Additional packages to exclude from pre-bundling
|
|
108
|
+
autoDetect: true, // Auto-detect installed React packages (default: true)
|
|
109
|
+
})
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Sub-path Exports
|
|
113
|
+
|
|
114
|
+
| Path | Contents |
|
|
115
|
+
|---|---|
|
|
116
|
+
| `what-react` | React API (hooks, createElement, Component, etc.) |
|
|
117
|
+
| `what-react/dom` | ReactDOM API (createRoot, createPortal, etc.) |
|
|
118
|
+
| `what-react/jsx-runtime` | JSX automatic runtime |
|
|
119
|
+
| `what-react/jsx-dev-runtime` | JSX dev runtime |
|
|
120
|
+
| `what-react/vite` | Vite plugin |
|
|
121
|
+
|
|
122
|
+
## Links
|
|
123
|
+
|
|
124
|
+
- [React Compat Showcase](https://react.whatfw.com)
|
|
125
|
+
- [Documentation](https://whatfw.com)
|
|
126
|
+
- [GitHub](https://github.com/CelsianJs/whatfw)
|
|
127
|
+
- [Benchmarks](https://benchmarks.whatfw.com)
|
|
128
|
+
|
|
129
|
+
## License
|
|
130
|
+
|
|
131
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "what-react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "React compatibility layer for What Framework — use React packages with signals under the hood",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -25,14 +25,14 @@
|
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"what-core": "^0.5.3"
|
|
27
27
|
},
|
|
28
|
-
"author": "",
|
|
28
|
+
"author": "ZVN DEV (https://zvndev.com)",
|
|
29
29
|
"license": "MIT",
|
|
30
30
|
"repository": {
|
|
31
31
|
"type": "git",
|
|
32
|
-
"url": "https://github.com/
|
|
32
|
+
"url": "https://github.com/CelsianJs/whatfw"
|
|
33
33
|
},
|
|
34
34
|
"bugs": {
|
|
35
|
-
"url": "https://github.com/
|
|
35
|
+
"url": "https://github.com/CelsianJs/whatfw/issues"
|
|
36
36
|
},
|
|
37
|
-
"homepage": "https://
|
|
37
|
+
"homepage": "https://react.whatfw.com"
|
|
38
38
|
}
|