使用 yarn 创建 React-ts 项目(使用 vite 和 tailwind)

准备工作 NodeJs:https://nodejs.org/zh-cn Prettier 插件:https://prettier.io/ 官方 Prettier VSCode 拓展等相关开发拓展 yarn 如果没有 yarn 可通过下面的命令安装: npm i -g yarn 或者可以去下载最近的 yarn2: https://yarnpkg.com/getting-started/install yarn 和 npm 相比可以并发的下载依赖,速度快很多,而 pnpm 在两者基础上更省空间 截止到目前 2023-10-12T23:54:08+08:00, yarn 已经相当稳定了,pnpm 可以算是激进派的选择, 个人推荐使用 yarn,它可以极大幅的节约拉取依赖的时间(相比于 NodeJs 自带的 npm) ...

十月 12, 2023 · 3 min · sslime336

React 在父组件中如何获取其包裹的子组件

十月 10, 2023 · 1 min · sslime336

React 重写组件 key 属性

在 React 中有一种方便的列表生成方式: userList.map((user, idx) => { <UserListItem id={idx} user={user} />; }); 但是如果直接这么写,会在 f12 调试的时候看到下面这样的报错: warning: each child in a list should have a unique "key" prop. ...

十月 10, 2023 · 1 min · sslime336

React State 应该永远只读

// 意思是你永远不要写出下面这样的代码 const [userList, setUserList] = useState([]); // ... // 直接修改了上面通过 useState 返回的 userList userList[idx].selected = !userList[idx].selected; setUserList(userList); ...

十月 10, 2023 · 1 min · sslime336