Installation

Add React Strudel Kit to an existing React app, connect a Play button and hear your first pattern.

Requirements

  • React 18 or later, with React DOM already installed in your app.
  • An ESM-capable bundler. The package has no CommonJS build.
  • A browser with Web Audio for playback.

TypeScript is optional. Declarations are included and support bundler and NodeNext module resolution.

Install the package

Run this in your React application’s directory:

Terminal
npm install react-strudel-kit

Import composition helpers from react-strudel-kit and the playback hook from react-strudel-kit/react. No provider or sample downloads are needed for this synthesized example.

Create a player

Save this component as GettingStarted.tsx and render <GettingStarted /> in your app. The class names are optional hooks for your own button styles.

GettingStarted.tsx
'use client'

import { chain, fn, pitch, sample, sequence } from 'react-strudel-kit'
import { useStrudel } from 'react-strudel-kit/react'

const firstPattern = chain(
  fn('note', sequence(pitch('c4'), pitch('e4'), pitch('g4'), pitch('b4'))),
  fn('instrument', sample('triangle')),
  fn('gain', 0.3),
  fn('cpm', 30),
)

export function GettingStarted() {
  const { play, stop, status, error } = useStrudel()

  return (
    <div role="group" aria-label="First pattern player">
      <button type="button" className="play-button"
        onClick={() => void play(firstPattern)}>Play</button>
      <button type="button" className="stop-button" onClick={stop}>Stop</button>
      <output aria-live="polite">{status}</output>
      {error && <p role="alert">{error.message}</p>}
    </div>
  )
}

Try it

This is the same component as the code above. Press Play to start the pattern and Stop to end it. The Strudel runtime loads on the first Play.

idle

Every useStrudel() call shares one transport. Starting another player replaces the current pattern. When adding live controls, use update while playing; changing controls while stopped should not start playback.

Next steps

Follow Your first song to understand notes and patterns, or Control it with React to build live controls. Use the API reference for the full playback contract and error states.