@berenjena/react-dev-panel

中文文档
2.5.1发布于 2026/06/22MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 6555

A React development panel with various tools and utilities.

原始使用文档
文档目录16 节
  1. Features
  2. Installation
  3. Quick Start
  4. Control Types
  5. Configuration
  6. Custom Hotkey
  7. Open from the console
  8. Panel Theme
  9. Event Handling
  10. Disabling in Production
  11. SSR / Next.js
  12. Documentation
  13. API Reference
  14. useDevPanel(sectionName, controls, options?)
  15. Contributing
  16. License

React Dev Panel

NPM Version npm package minimized gzipped size License: MIT Weekly Downloads

A lightweight, type-safe development panel for React that lets you control component state and props in real-time during development.

Features

  • One Hook: Single useDevPanel hook - no providers, no setup
  • 13 Control Types: Text, Number, Boolean, Select, Color, Range, Date, Button, LocalStorage, and more
  • Auto-Persistence: Optional localStorage sync for control values
  • Type-Safe: Full TypeScript support with IntelliSense
  • Themeable: 21 built-in themes + CSS custom properties
  • Lightweight: ~16 KB gzipped, zero runtime dependencies

Installation

npm install -D @berenjena/react-dev-panel

Quick Start

import { useState } from "react";
import { useDevPanel } from "@berenjena/react-dev-panel";

function App() {
    const [name, setName] = useState("John");
    const [age, setAge] = useState(25);
    const [theme, setTheme] = useState("dark");

    useDevPanel("Settings", {
        name: { type: "text", value: name, onChange: setName },
        age: { type: "number", value: age, min: 0, max: 100, onChange: setAge },
        theme: { type: "select", value: theme, options: ["light", "dark"], onChange: setTheme },
    });

    return <div>Hello, {name}!</div>;
}

That's it! Press Ctrl+Shift+A to toggle the panel.

Control Types

All 13 control types available:

{
  text: { type: "text", value: string, onChange: (v) => void }
  number: { type: "number", value: number, min?: number, max?: number, onChange: (v) => void }
  boolean: { type: "boolean", value: boolean, onChange: (v) => void }
  select: { type: "select", value: string, options: string[], onChange: (v) => void }
  multiselect: { type: "multiselect", value: string[], options: string[], onChange: (v) => void }
  color: { type: "color", value: string, onChange: (v) => void }
  range: { type: "range", value: number, min: number, max: number, step?: number, onChange: (v) => void }
  date: { type: "date", value: string, min?: string, max?: string, onChange: (v) => void }
  button: { type: "button", onClick: () => void }
  buttonGroup: { type: "buttonGroup", buttons: Array<{label: string, onClick: () => void}> }
  dragAndDrop: { type: "dragAndDrop", onChange: (files: FileList) => void }
  localStorage: { type: "localStorage", onRefresh?: () => void }
  separator: { type: "separator", variant?: "line" | "label" | "space" }
}

Common options (available on most controls):

  • label?: string - Display label
  • description?: string - Help text
  • disabled?: boolean - Disable control
  • persist?: boolean - Auto-save to localStorage

📖 Full control documentation →

Configuration

Custom Hotkey

useDevPanel("Settings", controls, {
    hotKeyConfig: { key: "d", ctrlKey: true, shiftKey: true },
});

Open from the console

Once the panel is in use, a devPanel helper is available on window so you can drive it straight from the browser console — handy when the hotkey clashes with another shortcut:

devPanel.open(); // show the panel
devPanel.close(); // hide it
devPanel.toggle(); // flip visibility (same as the hotkey)

It's registered automatically when the first (enabled) useDevPanel call mounts, so it isn't present in builds where the panel is disabled.

Panel Theme

useDevPanel("Settings", controls, {
    theme: "neon", // 21 built-in themes available
    panelTitle: "My Dev Panel",
});

Event Handling

Choose when controls trigger updates:

{
  type: "text",
  value: searchTerm,
  event: "onChange", // Update on every keystroke (default)
  onChange: setSearchTerm
}

{
  type: "text",
  value: apiKey,
  event: "onBlur", // Update only when focus is lost
  onChange: setApiKey
}

Disabling in Production

Use the enabled flag to turn the panel off at runtime. When false, the call is a no-op — the section is not registered and the panel does not mount. It defaults to true.

useDevPanel("Settings", controls, {
    enabled: import.meta.env.DEV, // Vite
    // enabled: process.env.NODE_ENV !== "production", // Webpack / Next / CRA
});

⚠️ enabled does not remove the panel from your bundle. It stops the panel from running, but the library code is still imported and shipped to users. To strip the code out of production builds entirely (e.g. a Vite plugin that stubs the package), see the Production & SSR guide.

SSR / Next.js

The package is import-safe on the server (it never touches document/localStorage at import time) and ships the "use client" directive, so it works under the Next.js App Router. The panel mounts and renders on the client only.

📖 Styling guide | Event handling | Advanced usage | Production & SSR

Documentation

Guides:

Live Examples:

  • Storybook - Interactive component demos
  • Run locally: npm run storybook

API Reference

useDevPanel(sectionName, controls, options?)

Parameters:

  • sectionName: string - Unique identifier for this control group
  • controls: ControlsGroup - Object mapping control keys to control definitions
  • options?: DevPanelProps - Optional configuration

Options:

{
  panelTitle?: string;           // Custom panel header
  theme?: string;                // Built-in theme name
  enabled?: boolean;             // Activate this call (default true; false = no-op)
  hotKeyConfig?: {               // Custom toggle hotkey
    key: string;
    ctrlKey?: boolean;
    shiftKey?: boolean;
    altKey?: boolean;
    metaKey?: boolean;
  }
}

enabled gates runtime behaviour only — it does not remove the panel from your bundle. See the Production & SSR guide for build-time stripping.

Contributing

Contributions are welcome! See CONTRIBUTING.md for guidelines.

Development:

git clone https://github.com/Berenjenas/react-dev-panel.git
cd react-dev-panel
npm install
npm run storybook

License

MIT © Berenjena


Links: NPM · GitHub · Issues · Berenjena


Made with ❤️ by the Berenjena team

版本与发布记录

@berenjena/react-dev-panel 共发布 19 个版本,首次发布于 2025/07/21;过去 12 个月发布了 5 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.5.1latest2026/06/224 个月前
2.5.02026/06/194 个月前
2.4.22026/01/239 个月前
2.4.12026/01/239 个月前
2.4.02026/01/239 个月前
2.3.02025/09/081.2 年前

其他发布通道:beta → 0.0.1-beta.6。

关于 @berenjena/react-dev-panel 的常见问题

@berenjena/react-dev-panel 是什么?

A React development panel with various tools and utilities.

如何安装 @berenjena/react-dev-panel?

在项目目录运行 npm install @berenjena/react-dev-panel,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=18.0.0)、react-dom(>=18.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@berenjena/react-dev-panel 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@berenjena/react-dev-panel 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@berenjena/react-dev-panel 可以商用吗?

@berenjena/react-dev-panel 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@berenjena/react-dev-panel 的下载量有多少?

根据 npm 官方下载统计,@berenjena/react-dev-panel 在 2026/10/08 – 2026/11/06 这 30 天内被下载 6,555 次,日均约 219 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@berenjena/react-dev-panel 还在维护吗?

最新版本 2.5.1 发布于 2026/06/22(4 个月前);至今共发布 19 个版本,其中过去 12 个月发布了 5 个;首次发布于 2025/07/21。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。