React Gantt - Zustand 教程
本教程将引导你使用 Vite 创建一个 React TypeScript 应用,集成 DHTMLX React Gantt 组件,并使用 Zustand 管理状态。
先决条件
- 具备 React、TypeScript、Vite 和 Zustand 的基本知识
- 建议:阅读 以了解数据绑定模式以及本教程所构建的
data.save回调的基础用法。
快速设置 - 创建项目
在开始之前,请先安装 Node.js。
创建一个 Vite React + TypeScript 项目:
npm create vite@latest react-gantt-zustand-demo -- --template react-ts
cd react-gantt-zustand-demo
现在让我们安装所需的依赖。
- 对于 npm:
npm install zustand @mui/material @mui/icons-material @emotion/react @emotion/styled
- 对于 yarn:
yarn add zustand @mui/material @mui/icons-material @emotion/react @emotion/styled
接着我们需要安装 React Gantt 包。
安装 React Gantt
按照 React Gantt 安装指南 中的说明安装。
在本教程中我们使用评估包:
npm install @dhtmlx/trial-react-gantt
或者
yarn add @dhtmlx/trial-react-gantt
如果你已经使用 Professional 包,请在命令和导入中把 @dhtmlx/trial-react-gantt 替换为 @dhx/react-gantt。
现在你可以启动开发服务器:
npm run dev
现在你应该可以在 http://localhost:5173 看到你的 React 项目正在运行。
注释
若要使 Gantt 占满 body 的全部空间,你需要移除 src 文件夹下的 App.css 中的默认样式,并添加以下样式:
#root {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
}