npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@marcelolsen/mini-react

v0.4.0

Published

A minimal React implementation with JSX support

Readme

MiniReact

A minimal React-like UI library built from scratch to understand how the virtual DOM, reconciliation, and hooks actually work.

Overview

This is a learning project, not a production framework. It implements the core ideas behind React—functional components, a virtual DOM, a reconciliation engine, hooks (useState, useEffect, useReducer, useRef, useMemo, useCallback), and the Context API—without the complexity of the real thing. The goal is to write code that is small enough to read in one sitting, but complete enough to actually build UIs with.

Quick Start

Requires Bun.

git clone https://github.com/MarcelOlsen/mini-react.git
cd mini-react
bun install
bun test

Usage

import { createElement, render, useState } from "@marcelolsen/mini-react";

const Counter = () => {
  const [count, setCount] = useState(0);

  return createElement(
    "button",
    { onClick: () => setCount(count + 1) },
    `Count: ${count}`
  );
};

render(createElement(Counter), document.getElementById("root")!);

JSX

Configure your build tool to use the MiniReact JSX runtime:

{
  "compilerOptions": {
    "jsx": "react-jsx",
    "jsxImportSource": "@marcelolsen/mini-react"
  }
}

Then write components normally:

const App = () => {
  return (
    <div>
      <h1>Hello</h1>
      <Counter />
    </div>
  );
};

What's Implemented

  • Virtual DOM & Reconciliation: Diff and patch the DOM efficiently.
  • Functional Components: Props, children, and composition.
  • Hooks: useState, useEffect, useReducer, useRef, useMemo, useCallback.
  • Context API: createContext / useContext for passing data through the tree.
  • Portals: Render children into a different DOM container while keeping the React tree structure.
  • Fragments: Group children without wrapper nodes.
  • JSX Runtime: Production and development JSX transforms (jsx, jsxs, jsxDEV).
  • Events: Standard DOM events attached directly to nodes.
  • Performance: Basic memoization via memo, useMemo, and useCallback.

Project Structure

src/
├── MiniReact.ts          # Main exports and JSX runtime
├── types.ts              # TypeScript definitions
├── vdom.ts               # Virtual DOM creation
├── reconciler.ts         # Reconciliation / diffing engine
├── hooks.ts              # Hook implementations
├── context.ts            # Context API
├── portals.ts            # Portals
├── events.ts             # Event system
└── jsx/
    ├── jsx-runtime.ts
    └── jsx-dev-runtime.ts

Development Phases

This project is built in incremental phases. Each phase has a clear goal, an implementation, and tests.

Alpha Track (Done)

  1. Element Creation & Basic Rendering
  2. Functional Components
  3. Virtual DOM & Reconciliation
  4. Prop Diffing & Children Reconciliation
  5. State with useState
  6. Event Handling
  7. Effects with useEffect
  8. Context API
  9. Portals and Fragments
  10. JSX Support
  11. useRef & useReducer

Stable Track (In Progress)

  1. Performance Optimization Suite — memo, useMemo, useCallback
  2. Error Boundaries & Resilience
  3. Async Features & Suspense
  4. Concurrent Features
  5. Developer Experience
  6. Server-Side Rendering
  7. Advanced Component Patterns
  8. Testing & Quality Assurance
  9. Production Optimizations

API

createElement(type, props, ...children)

Creates a virtual DOM element.

const el = createElement("div", { id: "app" }, "Hello");

render(element, container)

Renders a virtual element into a real DOM container.

render(createElement(App), document.getElementById("root")!);

useState(initialValue)

Returns a state tuple [value, setValue].

const [count, setCount] = useState(0);

useEffect(effect, deps?)

Runs side effects after render. Return a cleanup function if needed.

useEffect(() => {
  const id = setInterval(() => setTime(t => t + 1), 1000);
  return () => clearInterval(id);
}, []);

useReducer(reducer, initialState)

State management with a reducer function.

const [state, dispatch] = useReducer(counterReducer, { count: 0 });

useRef(initialValue)

Mutable reference that persists across renders without causing re-renders.

const inputRef = useRef<HTMLInputElement>(null);

useMemo(factory, deps) / useCallback(fn, deps)

Memoize expensive computations and stable function references.

createContext(defaultValue) / useContext(context)

Create and consume context to avoid prop drilling.

const ThemeContext = createContext("light");
const theme = useContext(ThemeContext);

createPortal(children, container)

Render children into a different DOM node.

createPortal(createElement(Modal), document.getElementById("modal-root")!);

Fragment

Group multiple elements without adding a wrapper to the DOM.

createElement(Fragment, null, child1, child2);

Testing

Tests run with Bun and use happy-dom for DOM simulation.

bun test              # run all tests
bun test --watch      # watch mode
bun test --coverage   # with coverage

Code Quality

Linting and formatting with Biome:

bunx biome check
bunx biome check --apply

License

MIT


Built to learn. Read the code, break it, fix it, understand it.