@critical-path/react

中文文档
0.15.11发布于 2026/11/05MITTypeScriptES Module构建来源已验证近 30 天下载 3585

React Context Provider and Hooks for Critical Path headless project management framework

原始使用文档
文档目录8 节
  1. 📦 Installation
  2. 💡 Usage Example
  3. 1. Wrap Application with Provider
  4. 2. Render Kanban Board
  5. 4. Unified Task Activity ( useTaskActivity )
  6. 5. Ladder of Abstraction ( useTimelineLadder & useCriticalP…
  7. 🧹 Stale Requests & Server Components
  8. 📄 License

@critical-path/react

React Context Provider & Hooks for Critical Path.

Upgrading? Upgrade every @critical-path/* package together. Coding agents: follow UPGRADING.md; breaking changes are marked BREAKING in this package's CHANGELOG.md.

@critical-path/react provides components and custom React hooks (useProjects, useTasks, useKanban, useTaskActivity, useComments, useAttachments, useTaskTransitions, useWorkflows, useDeliverables, useDeliverableSummary, useWebMCP) for rendering project management UIs in React and Next.js.


📦 Installation

npm install @critical-path/react @critical-path/client
# or
pnpm add @critical-path/react @critical-path/client

💡 Usage Example

1. Wrap Application with Provider

import { CriticalPathProvider } from '@critical-path/react';

export default function RootLayout({ children }) {
  return (
    <CriticalPathProvider options={{ baseUrl: '/api/critical-path' }}>
      {children}
    </CriticalPathProvider>
  );
}

2. Render Kanban Board

'use client';

import { useKanban } from '@critical-path/react';

export function Board({ projectId }: { projectId: string }) {
  const { columns, moveTask, loading } = useKanban(projectId);

  if (loading) return <div>Loading board...</div>;

  return (
    <div className="flex gap-4">
      {Object.entries(columns).map(([status, tasks]) => (
        <div key={status} className="column">
          <h2>{status} ({tasks.length})</h2>
          {tasks.map((task) => (
            <div key={task.id} className="card">
              <h3>{task.title}</h3>
              <button onClick={() => moveTask(task.id, 'done')}>Mark Done</button>
            </div>
          ))}
        </div>
      ))}
    </div>
  );
}
### 3. Manage Task Comments & Reactions

```tsx
'use client';

import { useComments } from '@critical-path/react';

export function TaskDiscussion({ taskId }: { taskId: string }) {
  const { comments, threads, addComment, addReaction, removeReaction } = useComments(taskId);

  return (
    <div className="discussion">
      {comments.map((comment) => (
        <div key={comment.id} className="comment">
          <p>{comment.content}</p>
          <div className="reactions flex gap-2">
            <button onClick={() => addReaction(comment.id, '👍')}>👍</button>
            <button onClick={() => addReaction(comment.id, '🚀')}>🚀</button>
            <span>{comment.reactions?.length || 0} reactions</span>
          </div>
        </div>
      ))}
    </div>
  );
}

4. Unified Task Activity (useTaskActivity)

Combines threaded comments with inline attachments and standalone attachments:

'use client';

import { useTaskActivity } from '@critical-path/react';

export function ActivityStream({ taskId }: { taskId: string }) {
  const { threads, standaloneAttachments, addComment, addReaction } = useTaskActivity(taskId);

  return (
    <div>
      {threads.map((thread) => (
        <div key={thread.id}>
          <p><strong>{thread.authorId}</strong>: {thread.content}</p>
          {thread.attachments.map((att) => (
            <a key={att.id} href={att.url}>{att.filename}</a>
          ))}
        </div>
      ))}
    </div>
  );
}

5. Ladder of Abstraction (useTimelineLadder & useCriticalPath)

Fluidly traverse between Macro phase health, Standard Gantt tasks with CPM critical paths, and Concrete deliverables/effort:

'use client';

import { useTimelineLadder, useCriticalPath } from '@critical-path/react';

export function ProjectTimelineView({ projectId }: { projectId: string }) {
  const { ladder, level, setLevel, macro, standard, concrete, loading } = useTimelineLadder(projectId, { level: 'all' });
  const { analysis } = useCriticalPath(projectId);

  if (loading) return <div>Synthesizing timeline ladder...</div>;

  return (
    <div>
      {/* Abstraction Slider */}
      <div className="flex gap-2 mb-4">
        <button onClick={() => setLevel('macro')}>Macro Phases</button>
        <button onClick={() => setLevel('standard')}>Standard Gantt</button>
        <button onClick={() => setLevel('concrete')}>Concrete Work</button>
        <button onClick={() => setLevel('all')}>Full Ladder</button>
      </div>

      {/* Macro Rung */}
      {macro && (
        <div className="macro-phase p-4 bg-slate-900 text-white rounded">
          <h2>Project Health: {macro.health} ({macro.overallProgressPercentage}% Complete)</h2>
          <p>Critical Path Duration: {macro.criticalPathDurationHours}h</p>
        </div>
      )}

      {/* Standard Rung */}
      {standard && (
        <div className="standard-gantt my-4">
          <h3>Gantt Tasks ({standard.tasks.length})</h3>
          {standard.tasks.map(item => (
            <div key={item.task.id} className={item.isCritical ? 'font-bold text-red-500' : ''}>
              {item.task.title} — ES: {item.schedule.earlyStart}h / EF: {item.schedule.earlyFinish}h (Slack: {item.schedule.totalSlack}h)
            </div>
          ))}
        </div>
      )}

      {/* Concrete Grounding Rung */}
      {concrete && (
        <div className="concrete-evidence">
          <h3>Ground Truth & Evidence</h3>
          {Object.entries(concrete).map(([taskId, evidence]) => (
            <div key={taskId} className="border p-2 rounded mb-2">
              <p>Task {taskId}: {evidence.attachments.length} files, {evidence.deliverables.length} deliverables</p>
              <p>Reality Delta: {evidence.realityDelta.hoursDelta > 0 ? `+${evidence.realityDelta.hoursDelta}h over estimate` : `${evidence.realityDelta.hoursDelta}h`}</p>
            </div>
          ))}
        </div>
      )}
    </div>
  );
}

🧹 Stale Requests & Server Components

Data hooks (useTasks, useProjects, useTaskActivity, useTimelineLadder, ...) abort their in-flight request when their inputs change or the component unmounts, so a slow response for a previous project or task can never overwrite newer data. The package is marked 'use client', so you can import the hooks from files used by Next.js server components and render them in client components.

📄 License

MIT © Critical Path

版本与发布记录

@critical-path/react 共发布 91 个版本,首次发布于 2026/08/24;过去 12 个月发布了 91 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.15.11latest2026/11/055 天前
0.15.102026/11/037 天前
0.15.92026/11/038 天前
0.15.82026/10/2813 天前
0.15.72026/10/2813 天前
0.15.62026/10/2813 天前

关于 @critical-path/react 的常见问题

@critical-path/react 是什么?

React Context Provider and Hooks for Critical Path headless project management framework

如何安装 @critical-path/react?

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

@critical-path/react 支持 TypeScript 吗?

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

@critical-path/react 支持 ESM 还是 CommonJS?

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

@critical-path/react 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=24.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@critical-path/react 可以商用吗?

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

@critical-path/react 的下载量有多少?

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

@critical-path/react 还在维护吗?

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