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

web-midi-hooks

v1.0.3

Published

React wrapper to pass Web MIDI API data to components using the Context API

Readme

Web MIDI Hooks

A React wrapper around the Web MIDI API using the useContext hook to pass MIDI data to components in your React app.

Getting Started

There are two main components to this package:

MidiProvider - This component handles connection to MIDI devices and collects incoming MIDI data using the Web MIDI API. This allows you to pass the incoming messages down the component tree without using props.

MidiDataContext - This component should be imported in each component you want to recieve MIDI data. It can be used anywhere in the app, without passing the MIDI data down through props, as it receives its data from the MidiProvider at the top level of your app.

To use in your project follow these steps:

  1. In the root file of your React app, typically index.js, import MidiProvider and wrap it around your React <App/> Component as shown below. This component will attempt to establish a connection to a MIDI device on app startup, and subsequently provide data based on incoming MIDI messages.

    import { MidiProvider } from './context/MidiProvider';
    
    ReactDOM.render(
      <React.StrictMode>
        <MidiProvider>
          <App />
        </MidiProvider>
      </React.StrictMode>,
      document.getElementById('root')
    );
  2. Create a component in your app that you want to import MIDI data into, and import MidiDataContext into this component, along with React's useContext hook as shown below. This example passes the connected MIDI device's name and incoming keyData which contains the key pressed and associated velocity value.

    import React, { useContext } from 'react';
    import { MidiDataContext } from '../context/MidiDataContext';
    
    const ExampleComponent = () => {
      const { deviceName, keyData } = useContext(MidiDataContext);
    
      return (
        <div>
          <h1>{deviceName}</h1>
          {keyData.map((key, i) => {
            return <p key={i}>{key.note}</p>
          })}
        </div>
      );
    };
       
    export default ExampleComponent;

Available Data

MidiDataContext has the following props available:

deviceName - string name of the connected device, provided by the device itself

keyData - an array of note/velocity objects representing key presses, in the form:

keyData = [{ 
  note: 68,
  velocity: 114
}]

pitch - number from 0-127 representing the pitch bend, where the midpoint 64 is no bend.

modulation - number from 0-127

errors - string that is populated when device connection problems occur