v18.2.0
|
react-dom v18.2.0
|
Mock
A React like framework, can be used to replace all of the react/react-dom api for test、learn、debug ...
import { useState, useCallback } from '@my-react/react';
import { createRoot } from '@my-react/react-dom';
const useCount = () => {
const [state, setState] = useState(0);
const add = useCallback(() => setState(i => i + 1), []);
const del = useCallback(() => setState(i => i - 1), []);
return [state, add, del];
};
const App = () => {
const [state, add, del] = useCount();
return (
<div>
<p>{state}</p>
<button onClick={add}>add</button>
<button onClick={del}>del</button>
</div>
);
};
createRoot(document.querySelector('#root')).render(<App />);Read-onlyA complete React alternative with powerful features for building modern web applications. From simple SPAs to complex 3D visualizations.
Drop-in replacement for React with the same API. Use your existing React code and libraries without modification.
Build custom renderers with our compact reconciler API. Support for Ink (Terminal), React Three Fiber, and more.
First-class Vite plugin support with HMR and fast refresh. Works with Remix and React Router v7 out of the box.
Run your Next.js applications with @my-react. Full SSR/SSG support with optimized hydration.
Powerful debugging with our custom DevTools extension. Inspect component trees, state, and performance in real-time.
Preserve component state during development with our hot refresh implementation for webpack, Vite, and Rspack.
Support for webpack, Vite, Rspack, Next.js, Remix, and React Router. Integrate with your favorite build tools.
Render 3D graphics with React Three Fiber and 2D canvas UI. Perfect for interactive visualizations and games.
10+
Packages
100%
React API Coverage
5+
Build Tool Integrations
3+
Custom Renderers
@my-react/react-reconciler-compact
A compact version of react-reconciler with the same APIs. Build custom renderers for any target platform.
Supported Renderers
Quick Start
pnpm run test:threepnpm run test:terminalimport { useState, useCallback } from '@my-react/react';
import { createReconciler } from '@my-react/react-reconciler-compact';
const Reconciler = createReconciler({
// Define the reconciler configuration here
});
const App = () => {
const [state, setState] = useState(0);
return (
<div>
<p>{state}</p>
<button onClick={() => setState(i => i + 1)}>add</button>
<button onClick={() => setState(i => i - 1)}>del</button>
</div>
);
};
const container = Reconciler.createContainer(
document.querySelector('#root')
);
Reconciler.updateContainer(<App />, container, null, () => {
console.log('Render complete');
});Read-only@my-react/react-refresh-tools
Run your Next.js applications with @my-react. Full SSR/SSG support with optimized hydration.
Note: Currently @my-react does not support React Server Components (RSC).
// 1. create a Next.js project
// 2. install @my-react
pnpm add @my-react/react @my-react/react-dom
pnpm add -D @my-react/react-refresh @my-react/react-refresh-tools
// 3. config next.config.js
const withNext = require('@my-react/react-refresh-tools/withNext');
module.exports = withNext(nextConfig);
// 4. start
pnpm run devRead-onlyNext.js + @my-react
body { font-family: sans-serif; -webkit-font-smoothing: auto; -moz-font-smoothing: auto; -moz-osx-font-smoothing: grayscale; font-smoothing: auto; text-rendering: optimizeLegibility; font-smooth: always; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; } h1 { font-size: 1.5rem; }
@my-react/react-vite
First-class Vite plugin support with HMR and fast refresh. Works with Remix and React Router v7 out of the box.
// 1. create a Vite React template
// 2. install @my-react
pnpm add @my-react/react @my-react/react-dom
pnpm add -D @my-react/react-refresh @my-react/react-vite
// 3. config vite.config.ts
import react from "@my-react/react-vite";
export default defineConfig({
plugins: [react({
// for remix
// remix: true,
// for react router v7
// reactRouter: true,
})],
});
// 4. start
pnpm run devRead-onlyVite + @my-react
body { font-family: sans-serif; -webkit-font-smoothing: auto; -moz-font-smoothing: auto; -moz-osx-font-smoothing: grayscale; font-smoothing: auto; text-rendering: optimizeLegibility; font-smooth: always; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; } h1 { font-size: 1.5rem; }
React Three Fiber + @my-react
Render 3D graphics with React Three Fiber. Perfect for interactive visualizations and games.
Tip: Click the DevTool button to inspect the component tree.
Examples
import { Canvas, useFrame } from "@my-react/react-three-fiber";
import { useRef, useState } from "react";
import type { ThreeElements } from "@my-react/react-three-fiber";
function Box(props: ThreeElements["mesh"]) {
const ref = useRef<THREE.Mesh>(null!);
const [hovered, hover] = useState(false);
const [clicked, click] = useState(false);
useFrame((state, delta) => (ref.current.rotation.x += delta));
return (
<mesh
{...props}
ref={ref}
scale={clicked ? 1.5 : 1}
onClick={(event) => click(!clicked)}
onPointerOver={(event) => hover(true)}
onPointerOut={(event) => hover(false)}
>
<boxGeometry args={[1, 1, 1]} />
<meshStandardMaterial color={hovered ? "hotpink" : "orange"} />
</mesh>
);
}
export const Exp = () => {
return (
<Canvas>
<ambientLight intensity={Math.PI / 2} />
<spotLight position={[10, 10, 10]} angle={0.15} penumbra={1} decay={0} intensity={Math.PI} />
<pointLight position={[-10, -10, -10]} decay={0} intensity={Math.PI} />
<Box position={[-1.2, 0, 0]} />
<Box position={[1.2, 0, 0]} />
</Canvas>
);
};
Read-only@canvas-ui/react + @my-react
Render 2D canvas UI with React. Build high-performance graphics and interactive interfaces.
Tip: Click the DevTool button to inspect the component tree.
import React from 'react'
import { Canvas, Text, Flex } from '@canvas-ui/react'
function HelloWorld() {
const containerStyle = {
width: 250,
flexDirection: 'column'
} as const
const textStyle = {
maxWidth: containerStyle.width,
maxLines: 1,
cursor: 'pointer',
fontSize: 14,
color: '#333'
} as const
const [text, setText] = React.useState('Hello, Canvas UI!')
const setTextRef = (ref) => {
console.info('Access underlying RenderText object:', ref)
}
const handlePointerDown = () => {
setText(text === 'Hello, Canvas UI!' ? 'Welcome to Canvas UI!' : 'Hello, Canvas UI!')
}
return (
<div style={{ height: '120px', border: '1px solid #ddd', borderRadius: '4px' }}>
<Canvas>
<Flex style={containerStyle}>
<Text
ref={setTextRef}
onPointerDown={handlePointerDown}
style={textStyle}
>
{text}
</Text>
<Text style={{ ...textStyle, marginTop: 8, fontSize: 12, color: '#666' }}>
Click the text above to see it change!
</Text>
</Flex>
</Canvas>
</div>
)
}
Read-only@my-react/devtools
A Chrome extension to debug @my-react apps, just like React DevTools. Inspect component trees, state, and performance in real-time.
// 1. clone the @my-react devtool repo
git clone https://github.com/MrWangJustToDo/myreact-devtools.git
// 2. init project
pnpm install
// 3. prepare
pnpm run build:packages
// 4. dev / build
// local dev by web
pnpm run dev:web
// install this extension in chrome
pnpm run build:extension
// 5. connect a @my-react app
// copy the connect command in the webUI into the @my-react app consoleRead-only
API Reference
Complete list of all @my-react packages and their exported APIs.
createELement | useState | render | createReactive | babel plugin | webpack plugin | vite plugin | rspack plugin | render |
cloneElement | useCallback | hydrate | reactive | refresh runtime | next.js plugin | | | <Box /> |
isValidElement | useMemo | renderToString | ref | | webpack loader | | | <Text /> |
Children | useReducer | findDOMNode | computed | | | | | <Static /> |
forwardRef | useRef | createPortal | watch | | | | | <Transform /> |
lazy | useEffect | unmountComponentAtNode | onBeforeMount | | | | | <NewLine /> |
createContext | useLayoutEffect | renderToNodeStream | onBeforeUnmount | | | | | |
createRef | useImperativeHandle | createRoot | onBeforeUpdate | | | | | |
memo | useContext | hydrateRoot | onMounted | | | | | |
Component | useDebugValue | renderToStaticMarkup | onUnmounted | | | | | |
PureComponent | useSignal | renderToStaticNodeStream | onUpdated | | | | | |
StrictMode | useDeferredValue | renderToPipeableStream | | | | | | |
Fragment | useId | renderToReadableStream | | | | | | |
Suspense | useInsertionEffect | | | | | | | |
createFactory | useSyncExternalStore | | | | | | | |
startTransition | useTransition | | | | | | | |