
mitt
A tiny event emitter for JavaScript that lets parts of your code publish and subscribe to events.
- Stars
- 11.9k
- Forks
- 495
- Licence
- MIT
- Language
- TypeScript
- Last update
- 2.2 years ago
- Type
- Library
No commits in over a year — check for forks or alternatives before adopting.
What it is
Mitt is a very small JavaScript library for sending named events between parts of a program. One piece of code can emit an event, and any number of other pieces can listen for it and react. It was made for the browser but the README says it works in any JavaScript runtime, with no dependencies.
- Letting UI components notify each other of changes without direct references
- Logging every event in an app by registering a handler on the wildcard '*' type
- Removing a specific handler with off() when a component unmounts
- Defining a typed set of events so emit() calls with the wrong payload type are flagged
Great for
- Frontend developers who want simple component-to-component messaging without a large framework
- Developers who want an API familiar from Node's EventEmitter but in a very small package
- Projects where bundle size matters and a full event system would be excessive
- TypeScript users who want typed event names and payloads
Not ideal for
- Projects that need the full Node EventEmitter feature set, since the README only says it shares names and ideas with it, not that it is a complete replacement
- Teams that need once-only listeners, error events, or other advanced features not described in the README
- Users who need support for very old browsers beyond IE9, since the README only states IE9+
How to get it
- 1
Install with a package manager
You'll need: Node.js and npm
Install with npm
npm install --save mitt - 2
Run it
- Install the package with npm install --save mitt
- Import it with import mitt from 'mitt'
- Create an emitter with const emitter = mitt()
- Register a listener with emitter.on('foo', handler) and fire it with emitter.emit('foo', data)
- 3
Get the most out of it
- Set "strict": true in tsconfig.json to get improved type inference, as the README recommends
- Pass a type parameter such as mitt<Events>() to get typed event names and payloads
- Use the '*' handler to observe all events for debugging or logging
- Use off() with a stored handler reference to remove a specific listener
Downloads
Strengths
- Very small, described in the README as under 200 bytes gzipped
- No dependencies and works in any JavaScript runtime per the README
- Methods do not depend on this, so they can be passed around as plain functions
Trade-offs
- Feature set is deliberately minimal; the API documentation lists only on, off, emit and all
- Manually firing the '*' wildcard handlers is not supported, per the README
How it compares
| Project | Stars | Type | Level | Updated | Best for |
|---|---|---|---|---|---|
| mitt (this) | 11.9k | Library | beginner | 2.2 years ago | Frontend developers who want simple component-to-component messaging without a large framework |
| fullcalendar | 20.7k | Library | intermediate | 21 days ago | Web developers adding a scheduling or event calendar to an existing site |
| ky | 17.1k | Library | beginner | 28 days ago | JavaScript or TypeScript developers who already use fetch and want less boilerplate |
Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.