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 ratingsYour rating
Log in to rate
Comments
0Log in to comment
Related Prompts
Linux Monitoring HTML Dashboard Generator
Generate a modern monitoring dashboard for Linux Ubuntu, integrating Docker status and disk IO throughputs, with multiple refresh rate options, built using React components and Quicksand font for a clean, sophisticated UI.
Investment Tracking Dashboard
Develop a comprehensive investment tracking dashboard application using React and JavaScript, showcasing portfolio performance, asset allocation, and investment growth, supporting stocks, bonds, and mutual funds with data visualization tools.
MQL5 Flexible Trade Management Pro
Design a powerful MQL5 code for flexible trade management on the chart, capturing profits and eliminating losing trades with precise calculations to protect the account.
Surprise Point-and-Click Game Generator
Ask the model to design or implement a point-and-click game based on AI choices and make the result surprising.