@my-react

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 ...

GitHubPlayground

Ecosystem

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-only
Features

Everything You Need

A complete React alternative with powerful features for building modern web applications. From simple SPAs to complex 3D visualizations.

Core

React Compatible

Drop-in replacement for React with the same API. Use your existing React code and libraries without modification.

Advanced

Custom Reconciler

Build custom renderers with our compact reconciler API. Support for Ink (Terminal), React Three Fiber, and more.

Popular

Vite Integration

First-class Vite plugin support with HMR and fast refresh. Works with Remix and React Router v7 out of the box.

RSC

React Server Components

End-to-end RSC pipeline with Flight streams, server actions, SSR decode, and hydration support.

SSR

Next.js Support

Run your Next.js applications with @my-react. Full SSR/SSG support with optimized hydration.

Beta

DevTools

Powerful debugging with our custom DevTools extension. Inspect component trees, state, and performance in real-time.

Hot Refresh

Preserve component state during development with our hot refresh implementation for webpack, Vite, and Rspack.

Rich Ecosystem

Support for webpack, Vite, Rspack, Next.js, Remix, and React Router. Integrate with your favorite build tools.

Experimental

Three.js & Canvas

Render 3D graphics with React Three Fiber and 2D canvas UI. Perfect for interactive visualizations and games.

New

Lynx Native Apps

Build cross-platform native apps with Lynx's dual-thread architecture. Full React API with native performance.

10+

Packages

100%

React API Coverage

5+

Build Tool Integrations

4+

Custom Renderers

Reconciler

@my-react/react-reconciler-compact

A compact version of react-reconciler with the same APIs. Build custom renderers for any target platform.

Supported Renderers

Ink

React Three Fiber

Quick Start

pnpm run test:threepnpm run test:terminal
import { 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

Next.js

@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).

Online ExampleView Template
// 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 dev
Read-only

Next.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;
  }

Vite

@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 dev
Read-only

Vite + @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;
  }

RSC

@my-react/react-server + Flight streams

Server Components with SSR + hydration. Decode Flight streams on the server and hydrate the same stream on the client.

View Example
// 1. install RSC packages
pnpm add @my-react/react-server
pnpm add -D @my-react/react-vite

// 2. configure Vite
import react from "@my-react/react-vite";

export default defineConfig({
  plugins: [
    react({
      rsc: true,
      rscEndpoint: "/__rsc",
      rscActionEndpoint: "/__rsc_action",
      ssr: {
        entryRsc: "/src/entry-rsc.tsx",
        entrySsr: "/src/entry-ssr.tsx",
      },
    }),
  ],
});

// 3. create entry-rsc + entry-ssr
// 4. run: pnpm dev
Read-only
Cross-Platform

Lynx

@my-react/react-lynx

Build cross-platform native applications with Lynx's dual-thread architecture. Full React API compatibility with Lynx-specific APIs for native performance.

Dual-Thread: Background thread for React, Main thread for native rendering

React Compatible: Use your existing React knowledge and components

Native Performance: Direct access to native APIs via worklets

Lynx DocsView Example
// lynx.config.ts
import { defineConfig } from "@lynx-js/rspeedy";
import { pluginMyReactLynx } from "@my-react/react-lynx/plugin";

export default defineConfig({
  plugins: [pluginMyReactLynx()],
});
Read-only
// src/index.tsx
import { root, useInitData, InitDataProvider } from "@my-react/react-lynx";

function App() {
  const initData = useInitData();
  
  return (
    <view className="container">
      <text className="title">Hello Lynx!</text>
      <text>{initData.message}</text>
    </view>
  );
}

root.render(
  <InitDataProvider>
    <App />
  </InitDataProvider>
);
Read-only

Lynx-Specific APIs

root.render()

Render to Lynx page

useInitData()

Get initData with auto re-render

useGlobalProps()

Get globalProps reactively

useMainThreadRef()

Create main-thread ref

runOnMainThread()

Execute on main thread

runOnBackground()

Execute on background

useLynxGlobalEventListener()

Early event binding

InitDataProvider

Context for initData

Three.js

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

@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

DevToolsBeta

@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 console
Read-only

Packages

API Reference

Complete list of all @my-react packages and their exported APIs.

createELementuseStaterendercreateReactivebabel pluginwebpack pluginvite pluginrspack pluginrenderrenderToFlightStreamroot.render
cloneElementuseCallbackhydratereactiverefresh runtimenext.js plugin<Box />createFlightServeruseInitData
isValidElementuseMemorenderToStringrefwebpack loader<Text />createFlightClientuseGlobalProps
ChildrenuseReducerfindDOMNodecomputed<Static />useMainThreadRef
forwardRefuseRefcreatePortalwatch<Transform />useLynxGlobalEventListener
lazyuseEffectunmountComponentAtNodeonBeforeMount<NewLine />runOnMainThread
createContextuseLayoutEffectrenderToNodeStreamonBeforeUnmountrunOnBackground
createRefuseImperativeHandlecreateRootonBeforeUpdateInitDataProvider
memouseContexthydrateRootonMountedGlobalPropsProvider
ComponentuseDebugValuerenderToStaticMarkuponUnmountedMainThreadRef
PureComponentuseSignalrenderToStaticNodeStreamonUpdatedregisterDataProcessors
StrictModeuseDeferredValuerenderToPipeableStreamwithInitDataInState
FragmentuseIdrenderToReadableStream
SuspenseuseInsertionEffect
createFactoryuseSyncExternalStore
startTransitionuseTransition