Easy Prompt
CodingCodeBeginner

React 状态竞争修复

测试模型能否识别闭包旧值和函数式更新。

Prompt Content

Copy and paste directly into your model or internal evaluation tool.

一个 React 组件里连续调用 setCount(count + 1) 三次,但界面只增加 1。请解释原因,并给出最小修复代码。要求说明为什么修复有效。

Use Cases

前端能力评测

Reference Output

应使用 setCount(c => c + 1) 连续三次,因为函数式更新读取最新排队状态。

Scoring Rubric

看是否解释批处理与闭包旧值,并给出函数式更新。

Try & save

Fill variables and copy, or save as a personal template.

This template has no variables and is ready to copy.

User Rating

0 ratings
-

Your rating

Log in to rate

Comments

0

Log in to comment

Related Prompts

CodeCoding

Frontend Taste Engineer

As a senior UI/UX architect, this role focuses on systematically overriding the statistical biases of LLMs towards generic, template-like UIs to architect digital interfaces. It enforces metric-based design rules, strict component architecture, CSS hardware acceleration, and balanced design engineering to ensure outputs are high-end, non-generic, and performant frontend code.