Browser extension that allows you to inspect a Preact component hierarchy, including props and state.
Firstly, we need to import preact/debug
somewhere to initialize the connection
to the extension. Make sure that this import is the first import in your
whole app.
// Must be the first import
import "preact/debug";
Then, download the Preact Devtools extension for your browser:
- Use
npm run dev
to start a demo page - Use
npm run watch
to rebuild all extensions on any code changes - Use
npm run build:firefox
ornpm run build:chrome
to create a release build
Chrome:
- Go to extensions page
- Enable developer mode
- Click "Load unpacked"
- Select
dist/chrome/
folder
Firefox:
- Go to addons page
- Click the settings icon
- Select "Debug addons"
- Click "Load temporary addon"
- Select the
manifest.json
indist/firefox/
preact-devtools
supports an inline build target, where the devtools
can be embedded into any page without any restrictions like rendering
it into iframe
s. Don't forget to include the css file too.
import "preact-devtools/dist/preact-devtools.css";
import { attach, createRenderer, renderDevtools } from "preact-devtools";
import { options } from "preact";
// Instantiate devtools backend and attach it to preact
// - store -> The backing store for the devtools
// - destroy -> unlisten and restore previous `preact.options`
const { store, destroy } = attach(options, createRenderer);
// Render the actual devtools into the specified DOM node
renderDevtools(store, document.getElementById("devtools"));