DrillLab
练习Practice

动手做Get your hands on it

练习跟着课文走 —— 每节课尾都有本课的练习。这一页是全部练习的总库,想集中刷题的时候来。 每个练习都写清了它来自哪一节,卡住了就回去看那一节。Practice follows the lessons — every lesson ends with the exercises for that lesson. This page is the whole library, for when you want to drill in one sitting. Each exercise names the lesson it came from, so you can go back when you stall.

0 / 148个做对过you got right

练习Exercises

筛出 56 个练习(共 148 个) · 第 2 / 5 页。Showing 56 of 148 · page 2 / 5.
来自From 列表渲染与 keyRendering a list, and the key prop · React 考试React exam
L1认出来Spot it这个列表该用什么当 keyWhat should this list use as its key

notes 里每条是 { id: number; title: string; content: string }, 用户可以删除任意一条。下面哪个是最合适的 key?

Each item in notes is { id: number; title: string; content: string }, and the user can delete any of them. Which of these is the best key?

先选一个选项Pick an option first
来自From 列表渲染与 keyRendering a list, and the key prop · React 考试React exam
L1认出来Spot it哪一段什么都不会渲染Which one renders nothing at all

下面哪一段会导致表格里一行都不出现(而且不报错)?

Which of these makes the table show no rows at all, without reporting an error?

先选一个选项Pick an option first
来自From 派生数据与状态提升:什么不该做成 stateValues you can compute, and lifting state up: what should not be state · React 考试React exam
L1认出来Spot it哪个应该做成 stateWhich one should become state

假设要给 Notes Manager 加一个「显示当前有几条笔记」的文字。 这个数字应该怎么实现?

Say you have to add a line to Notes Manager that shows how many notes there are right now. How should that number be produced?

先选一个选项Pick an option first
来自From 派生数据与状态提升:什么不该做成 stateValues you can compute, and lifting state up: what should not be state · React 考试React exam
L1认出来Spot it这个 state 该住哪Where should this state live

假设要加一个搜索框(在 NoteForm 上方,属于 NoteManager 的直接子元素), 输入关键词后表格只显示匹配的笔记。 搜索关键词这个 state 该放在哪?

Say you add a search box above NoteForm, as a direct child of NoteManager. Once a keyword is typed, the table shows only the notes that match. Where should the state holding that keyword go?

先选一个选项Pick an option first
来自From 先读题:三个任务、一条硬约束、四个测试Read the question first: three tasks, one rule you must not break, four tests · React 考试React exam
L1认出来Spot it哪一处改动会让测试挂掉Which change makes a test fail

README 只说了「不得修改任何 data-testid」。 下面哪些改动也会让现有测试失败?(多选)

The README says only that no data-testid may be changed. Which of the changes below also break the existing tests? (more than one)

这题是多选。More than one answer is correct.

先选一个选项Pick an option first
来自From 先读题:三个任务、一条硬约束、四个测试Read the question first: three tasks, one rule you must not break, four tests · React 考试React exam
L1认出来Spot it题目没写但测试在查的是哪一条The requirement the task never states but a test checks

README 的三个 Task 里没提到某个要求, 但四个测试里有一条专门在查它。是哪个?

One requirement is never mentioned in the three Tasks of the README, yet one of the four tests checks exactly that. Which one is it?

先选一个选项Pick an option first
来自From 先读题:三个任务、一条硬约束、四个测试Read the question first: three tasks, one rule you must not break, four tests · React 考试React exam
L1排顺序Order it把上手顺序排对Put the starting steps in order

拿到这个项目,最合理的动作顺序是什么?

You just received this project. What is the most sensible order to work in?

1写代码:三个 handler 逐个实现Write the code: implement the three handlers one at a time
2npm install,然后 npx vitest run 拿到基线npm install, then npx vitest run to get a baseline
3读 NoteForm / NoteTable / NoteItem,确认它们已经完整、不用改Read NoteForm / NoteTable / NoteItem and confirm they are already complete and need no change
4读 README + 读测试文件,抄下所有验收标准Read the README and the test file, and write down every acceptance criterion
5npx vitest run 验证,再 npm run dev 手动点一遍Verify with npx vitest run, then npm run dev and click through it by hand
6读 types/Note.ts,确认数据形状和 id 的类型Read types/Note.ts to confirm the shape of the data and the type of id
来自From 四个测试逐条读,以及它们的盲区The four tests read line by line, and what they fail to catch · React 考试React exam
L1认出来Spot it哪个实现能骗过全部四个测试但其实是错的Which implementation passes all four tests and is still wrong

下面哪个 handleDelete 能让四个测试全部通过, 但明显违反题目要求?

Which handleDelete below makes all four tests pass while clearly breaking what the task asks for?

先选一个选项Pick an option first
来自From 四个测试逐条读,以及它们的盲区The four tests read line by line, and what they fail to catch · React 考试React exam
L1认出来Spot it这个测试失败是因为什么Why this test fails

你写的 handleSubmitNote setNotes((prev) => [...prev, submittedNote]), 但自己加的测试报「找不到 My Title」。 测试代码是 userEvent.click(btn); expect(list).toHaveTextContent("My Title")。 最可能的原因?

Your handleSubmitNote is setNotes((prev) => [...prev, submittedNote]), but the test you added reports that My Title cannot be found. The test code is userEvent.click(btn); expect(list).toHaveTextContent("My Title"). What is the most likely reason?

先选一个选项Pick an option first
来自From 读题:三条要求,每一条都在指定一种写法Reading the question: three requirements, and each one decides how you write it · React 考试React exam
L1认出来Spot it如果参数改成 Promise 数组会怎样What happens if the parameter becomes an array of Promises

假设签名改成 runTasks(promises: Promise<T>[], limit: number), 调用方写 runTasks([task1(), task2(), task3()], 2)。 会发生什么?

Suppose the signature becomes runTasks(promises: Promise<T>[], limit: number) and the caller writes runTasks([task1(), task2(), task3()], 2). What happens?

先选一个选项Pick an option first
来自From 读题:三条要求,每一条都在指定一种写法Reading the question: three requirements, and each one decides how you write it · React 考试React exam
L1认出来Spot it为什么不能直接用 Promise.allSettledWhy Promise.allSettled on its own is not the answer

有人写 return Promise.allSettled(tasks.map((t) => t()))。 它满足几条要求?

Someone writes return Promise.allSettled(tasks.map((t) => t())). How many of the requirements does it meet?

先选一个选项Pick an option first
来自From GraphQL 是什么:一份 schema 加一堆 resolverWhat GraphQL is: one schema plus a set of resolvers · Federation 考试Federation exam
L1认出来Spot it哪些字段是标量Which fields are scalars

看真实 schema 里的 type Order。 下面哪些字段的类型是标量(不能再往下展开)?(多选)

Look at type Order in the real schema. Which of these fields have a scalar type — one that cannot be expanded any further? (Select all that apply.)

GraphQL SDL源项目From source
1type Order {
2 id: ID!
3 userId: ID!
4 status: OrderStatus!
5 totalAmount: Float!
6 items: [OrderItem!]!
7 createdAt: String!
8 shippingInfo: ShippingInfo
9}
Source: graphql-federation-practice/node-subgraph/src/schema.graphql

这题是多选。More than one answer is correct.

先选一个选项Pick an option first