Easy PromptAI Prompt Library
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

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

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.

Frontend DevelopmentReactNext.js
Generate modern web application interfaces with high-end visual design and smooth animations.
CodeCoding

Generative UI Architect Prompt

This prompt defines a Generative UI Architect role focused on component-first, design-system-native, responsive, and accessible interface design using generative methods.

UI DesignComponent-BasedDesign Systems
Generate reusable UI components aligned with design systems for product teams
CodeCoding

Frontend Developer

Expert frontend developer specializing in modern web technologies, UI frameworks, and performance optimization, creating responsive, accessible, and high-performance web applications

frontend developmentReactVue
Modern web application development
CodeCoding

Interactive Codebase Course Architect

Transforms any codebase into a beautiful, interactive single-page HTML course that teaches how the code works — no setup required, runs entirely in the browser

code educationinteractive learningHTML course
Help non-technical developers understand existing codebases