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

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.

10+

Packages

100%

React API Coverage

5+

Build Tool Integrations

3+

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

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
@my-react DevTools

Packages

API Reference

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

createELementuseStaterendercreateReactivebabel pluginwebpack pluginvite pluginrspack pluginrender
cloneElementuseCallbackhydratereactiverefresh runtimenext.js plugin<Box />
isValidElementuseMemorenderToStringrefwebpack loader<Text />
ChildrenuseReducerfindDOMNodecomputed<Static />
forwardRefuseRefcreatePortalwatch<Transform />
lazyuseEffectunmountComponentAtNodeonBeforeMount<NewLine />
createContextuseLayoutEffectrenderToNodeStreamonBeforeUnmount
createRefuseImperativeHandlecreateRootonBeforeUpdate
memouseContexthydrateRootonMounted
ComponentuseDebugValuerenderToStaticMarkuponUnmounted
PureComponentuseSignalrenderToStaticNodeStreamonUpdated
StrictModeuseDeferredValuerenderToPipeableStream
FragmentuseIdrenderToReadableStream
SuspenseuseInsertionEffect
createFactoryuseSyncExternalStore
startTransitionuseTransition