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

@fluxgpu/react

v5.3.0

Published

React hooks and components for FluxGPU - GPUCanvas, useGPUFrame, and more

Readme

@fluxgpu/react

React hooks and components for FluxGPU.

Installation

pnpm add @fluxgpu/react
# Dependencies are re-exported, but you can also install directly:
# pnpm add @fluxgpu/engine @fluxgpu/host-browser @fluxgpu/contracts

Hooks

useGPU

Initialize GPU adapter and executor from a canvas ref.

import { useRef } from 'react';
import { useGPU } from '@fluxgpu/react';

function App() {
  const canvasRef = useRef<HTMLCanvasElement>(null);
  const { adapter, executor, error, isLoading } = useGPU(canvasRef);

  if (isLoading) return <div>Loading WebGPU...</div>;
  if (error) return <div>Error: {error.message}</div>;

  return <canvas ref={canvasRef} width={800} height={600} />;
}

useGPUFrame

Run a render callback every frame.

import { useGPU, useGPUFrame } from '@fluxgpu/react';
import type { ICommandEncoder } from '@fluxgpu/contracts';

function App() {
  const canvasRef = useRef<HTMLCanvasElement>(null);
  const { executor } = useGPU(canvasRef);

  useGPUFrame(executor, (encoder: ICommandEncoder, deltaTime: number) => {
    // Render logic here
  });

  return <canvas ref={canvasRef} width={800} height={600} />;
}

useAnimationFrame

Low-level animation frame hook.

import { useAnimationFrame } from '@fluxgpu/react';

useAnimationFrame((deltaTime, time) => {
  // Called every frame
}, active);

useMouse

Track normalized mouse position (-1 to 1).

import { useMouse } from '@fluxgpu/react';

const canvasRef = useRef<HTMLCanvasElement>(null);
const { x, y } = useMouse(canvasRef);

Components

GPUCanvas

Self-contained GPU canvas with automatic lifecycle management.

import { GPUCanvas } from '@fluxgpu/react';
import type { ICommandEncoder } from '@fluxgpu/contracts';
import { AdapterExecutor } from '@fluxgpu/react';

function App() {
  const handleReady = (executor: AdapterExecutor) => {
    // Initialize pipelines and buffers
  };

  const handleRender = (encoder: ICommandEncoder, deltaTime: number) => {
    // Render frame
  };

  return (
    <GPUCanvas
      width={800}
      height={600}
      onReady={handleReady}
      onRender={handleRender}
      autoStart={true}
    >
      <div className="overlay">FPS: 60</div>
    </GPUCanvas>
  );
}

GPUCanvas Props

| Prop | Type | Default | Description | |------|------|---------|-------------| | width | number | 800 | Canvas width | | height | number | 600 | Canvas height | | devicePixelRatio | boolean | true | Use device pixel ratio | | autoStart | boolean | true | Auto-start render loop | | onReady | (executor: AdapterExecutor) => void | - | Called when GPU is ready | | onRender | (encoder: ICommandEncoder, deltaTime: number) => void | - | Called each frame | | onError | (error: Error) => void | - | Called on error |

GPUStats

Display GPU statistics overlay.

import { GPUStats } from '@fluxgpu/react';

<GPUStats position="top-right" />

Full Example

import { useRef, useState, useCallback, useMemo } from 'react';
import { useGPU, useGPUFrame, BrowserGPUAdapter } from '@fluxgpu/react';
import type { ICommandEncoder, IComputePipeline, IRenderPipeline, IBuffer, IBindGroup } from '@fluxgpu/contracts';
import { BufferUsage } from '@fluxgpu/contracts';
import { AdapterExecutor } from '@fluxgpu/react';

const PARTICLE_COUNT = 10000;

export default function ParticleDemo() {
  const canvasRef = useRef<HTMLCanvasElement>(null);
  const { executor, isLoading, error } = useGPU(canvasRef);
  
  const resourcesRef = useRef<{
    computePipeline: IComputePipeline;
    renderPipeline: IRenderPipeline;
    particleBuffer: IBuffer;
    computeBindGroup: IBindGroup;
    renderBindGroup: IBindGroup;
  } | null>(null);

  // Initialize resources when executor is ready
  useCallback(async () => {
    if (!executor || resourcesRef.current) return;
    
    const adapter = executor.getAdapter() as BrowserGPUAdapter;
    
    // Create shader modules
    const computeModule = executor.createShaderModule(computeShaderCode);
    const vertexModule = executor.createShaderModule(vertexShaderCode);
    const fragmentModule = executor.createShaderModule(fragmentShaderCode);
    
    // Create pipelines
    const computePipeline = await executor.createComputePipeline({
      shader: computeModule,
      entryPoint: 'main',
    });
    
    const renderPipeline = await executor.createRenderPipeline({
      vertex: { shader: vertexModule, entryPoint: 'main' },
      fragment: {
        shader: fragmentModule,
        entryPoint: 'main',
        targets: [{ format: executor.getPreferredFormat() }],
      },
    });
    
    // Create buffers
    const particleBuffer = executor.createBuffer({
      size: PARTICLE_COUNT * 32,
      usage: BufferUsage.STORAGE | BufferUsage.COPY_DST,
    });
    
    // Create bind groups
    const computeBindGroup = adapter.createBindGroup({
      layout: computePipeline.getBindGroupLayout(0),
      entries: [{ binding: 0, resource: { buffer: particleBuffer } }],
    });
    
    const renderBindGroup = adapter.createBindGroup({
      layout: renderPipeline.getBindGroupLayout(0),
      entries: [{ binding: 0, resource: { buffer: particleBuffer } }],
    });
    
    resourcesRef.current = {
      computePipeline,
      renderPipeline,
      particleBuffer,
      computeBindGroup,
      renderBindGroup,
    };
  }, [executor]);

  // Render loop
  useGPUFrame(executor, (encoder: ICommandEncoder, deltaTime: number) => {
    const resources = resourcesRef.current;
    if (!resources) return;
    
    // Compute pass
    const computePass = encoder.beginComputePass();
    computePass.setPipeline(resources.computePipeline);
    computePass.setBindGroup(0, resources.computeBindGroup);
    computePass.dispatchWorkgroups(Math.ceil(PARTICLE_COUNT / 256));
    computePass.end();
    
    // Render pass
    const renderTarget = executor!.getCurrentTexture();
    if (renderTarget) {
      const renderPass = encoder.beginRenderPass({
        colorAttachments: [{
          view: renderTarget.createView(),
          clearValue: { r: 0, g: 0, b: 0, a: 1 },
          loadOp: 'clear',
          storeOp: 'store',
        }],
      });
      renderPass.setPipeline(resources.renderPipeline);
      renderPass.setBindGroup(0, resources.renderBindGroup);
      renderPass.draw(PARTICLE_COUNT * 6);
      renderPass.end();
    }
  });

  if (isLoading) return <div>Loading...</div>;
  if (error) return <div>Error: {error.message}</div>;

  return (
    <canvas
      ref={canvasRef}
      width={800 * devicePixelRatio}
      height={600 * devicePixelRatio}
      style={{ width: 800, height: 600 }}
    />
  );
}

Re-exports

For convenience, this package re-exports commonly used types and classes:

import {
  // Hooks
  useGPU,
  useGPUFrame,
  useAnimationFrame,
  useMouse,
  
  // Components
  GPUCanvas,
  FluxCanvas,
  GPUStats,
  
  // Re-exported from @fluxgpu/engine
  AdapterExecutor,
  
  // Re-exported from @fluxgpu/host-browser
  BrowserGPUAdapter,
  
  // Re-exported types from @fluxgpu/contracts
  type IGPUAdapter,
  type ICommandEncoder,
  type IBuffer,
  type ITexture,
} from '@fluxgpu/react';