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

@woby/react

v1.0.7

Published

This project demonstrates how to integrate React, Woby, and Web Components in a single application. It shows how React components can be converted to Web Components and used alongside Woby components.

Downloads

12

Readme

React + Woby + Web Components Integration

This project demonstrates how to integrate React, Woby, and Web Components in a single application. It shows how React components can be converted to Web Components and used alongside Woby components.

Features

  1. React components with state management
  2. Woby components with observable-based reactivity
  3. React components converted to Web Components using @r2wc/react-to-web-component
  4. Communication between all component types
  5. Custom hooks for rendering components (useWoby and useReact)

Project Structure

  • src/index.ts - Library entry point exporting integration hooks
  • src/useReact.ts - Hook for rendering React components in Woby environment
  • src/useWoby.ts - Hook for rendering Woby components in React environment
  • examples/ - Example implementations and demonstrations
  • examples/react-components/ - React component examples
  • examples/@woby/components/ - Woby component examples

Repository

Live Demo

You can try this demo live on CodeSandbox. To deploy:

  1. Create a new GitHub repository with the example files
  2. Import the repository to CodeSandbox
  3. The example will automatically run with hot module replacement

The examples showcase:

  • React components with state management
  • Woby components with observable-based reactivity
  • React components converted to Web Components
  • Communication between all component types

Library Usage

Installation

npm install usereact

useReact Hook

Renders React components within a Woby environment.

/** @jsxImportSource woby */
import { useReact } from 'usereact';
import { ReactCounter } from './ReactCounter';

const UseReactExample = () => {
  const reactContainerRef = useReact(ReactCounter, {
    initialValue: 5,
    onValueChange: (value) => {
      console.log('Counter value changed to:', value);
    }
  });

  return (
    <div class="text-center m-2">
      <h2>Woby Env</h2>
      <h3>useReact Hook Examples</h3>
      <div ref={reactContainerRef} />
    </div>
  );
};

useWoby Hook

Renders Woby components within a React environment.

import { useWoby } from 'usereact';
import { WobyCounter } from './WobyCounter';

function App() {
  // Use the Woby component hook
  const wobyContainerRef = useWoby(WobyCounter, {});

  return (
    <div>
      <h1>My App</h1>
      <div ref={wobyContainerRef} />
    </div>
  );
}

How It Works

React to Web Component Conversion

We use @r2wc/react-to-web-component to convert React components to Web Components:

import r2wc from '@r2wc/react-to-web-component';
import { ReactCounter } from './examples/react-components/ReactCounter';

// Convert the React component to a web component
const ReactCounterWebComponent = r2wc(ReactCounter, {
  props: {
    initialValue: 'number',
    onValueChange: 'function'
  }
});

// Register the custom element
customElements.define('react-counter', ReactCounterWebComponent);

Using the useReact Hook

The useReact hook allows you to render React components dynamically within Woby applications:

/** @jsxImportSource woby */
import { useReact } from 'usereact';
import { ReactCounter } from './examples/react-components/ReactCounter';

const UseReactExample = () => {
  // Use the React component hook
  const reactContainerRef = useReact(ReactCounter, {
    initialValue: 10,
    onValueChange: (value) => {
      console.log('Value changed to:', value);
    }
  });

  return (
    <div class="text-center m-2">
      <h2>Woby Env</h2>
      <h3>useReact Hook Examples</h3>
      <div ref={reactContainerRef} />
    </div>
  );
};

Using the useWoby Hook

The useWoby hook allows you to render Woby components within React:

import { useWoby } from 'usereact';
import { WobyCounter } from './examples/@woby/components/WobyCounter';

function App() {
  // Use the Woby component hook
  const wobyContainerRef = useWoby(WobyCounter, {});

  return (
    <div>
      <h1>My App</h1>
      <div ref={wobyContainerRef} />
    </div>
  );
}

Using the Web Component

Once registered, the web component can be used in HTML:

<react-counter initial-value="5"></react-counter>

Or in React with a ref to handle events:

<react-counter 
  ref={webComponentRef}
  initial-value={5}
></react-counter>

Web Component Events

Web components can emit events that can be listened to in JavaScript:

const webComponent = document.querySelector('react-counter');
webComponent.addEventListener('valuechange', (event) => {
  console.log('Value changed to:', event.detail);
});

Running the Project

  1. Install dependencies:

    pnpm install
  2. Start the development server:

    pnpm run dev
  3. Visit http://localhost:5173 to see the main demo

  4. Visit http://localhost:5173/web-component-demo.html to see the standalone web component demo

Integration Points

  • React components use useState for state management
  • Woby components use observables for reactivity
  • Web components bridge the gap between React and vanilla JavaScript
  • All component types can communicate through refs and callbacks
  • Custom hooks provide a unified interface for rendering different component types

API Reference

useReact(component, props?)

Renders a React component in a Woby environment.

Parameters:

  • component: The React component to render
  • props (optional): Props to pass to the React component

Returns: An observable ref that should be attached to a DOM element.

useWoby(component, props?)

Renders a Woby component in a React environment.

Parameters:

  • component: The Woby component to render
  • props (optional): Props to pass to the Woby component

Returns: A ref that should be attached to a DOM element.

Deployment

See DEPLOYMENT.md for instructions on deploying to CodeSandbox.