Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx agentmods add rules/wangqiqi/cursor-ai-rules/react-basics-stategit clone --depth 1 https://github.com/wangqiqi/cursor-ai-rulesWhat it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5 | $0.00000 | $0.00606 |
| Opus 5 | $0.00000 | $0.00303 |
| Sonnet 5 | $0.00000 | $0.00121 |
| Haiku 4.5 | $0.00000 | $0.00061 |
Grade A, and why
react-basics-state scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 95 lines — stays where its author put it; the contents beside it link to each section on GitHub.
React 状态管理 (State)
本规则由
@react-basics引用
Context API + useReducer
const AuthContext = createContext()
const authReducer = (state, action) => {
switch (action.type) {
case 'LOGIN_START':
return { ...state, loading: true, error: null }
case 'LOGIN_SUCCESS':
return { ...state, loading: false, user: action.payload, isAuthenticated: true }
case 'LOGIN_FAILURE':
return { ...state, loading: false, error: action.payload, isAuthenticated: false }
case 'LOGOUT':
return { user: null, isAuthenticated: false, loading: false, error: null }
default:
return state
}
}
export const AuthProvider = ({ children }) => {
const [state, dispatch] = useReducer(authReducer, initialState)
const login = async (credentials) => {
dispatch({ type: 'LOGIN_START' })
try {
const user = await fetch('/api/auth/login', { ... }).then(r => r.json())
localStorage.setItem('authToken', user.token)
dispatch({ type: 'LOGIN_SUCCESS', payload: user })
} catch (error) {
dispatch({ type: 'LOGIN_FAILURE', payload: error.message })
}
}
const logout = () => {
localStorage.removeItem('authToken')
dispatch({ type: 'LOGOUT' })
}
return (
<AuthContext.Provider value={{ ...state, login, logout }}>
{children}
</AuthContext.Provider>
)
}
export const useAuth = () => {
const context = useContext(AuthContext)
if (!context) throw new Error('useAuth must be used within AuthProvider')
return context
}
使用示例
function App() {
return (
<AuthProvider>
<Dashboard />
</AuthProvider>
)
}
function Dashboard() {
const { user, isAuthenticated, login, logout, loading } = useAuth()
if (!isAuthenticated) return <LoginForm onLogin={login} loading={loading} />
return <div><h1>欢迎, {user.name}</h1><button onClick={logout}>登出</button></div>
}
状态管理选择
| 场景 | 推荐方案 |
|---|---|
| 局部 UI 状态 | useState |
| 跨组件共享 | Context + useReducer |
| 服务端状态 | TanStack Query / SWR |
| 复杂全局状态 | Zustand / Redux |
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 2d ago First seen · 95 lines · 0 tokens per session scan A f3e7975897d7
react-basics-state is a cursor rule published in the GitHub repository wangqiqi/cursor-ai-rules (15 stars, last pushed 3mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 606 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.
Other cursor rules, from other repositories
react-vite-web
Cursor rule "react-vite-web" from WellApp-ai/Well, covering web rules (react + vite), routing, component structure, state management and api integration.
frontend-patterns
React/TypeScript patterns for src/ code.
new-component
Workflow for creating new React components.
frontend-architecture
Vite + React SPA architecture - directory layout, providers, bundle splitting. Tailwind styling in tailwind.mdc.
performance-optimization-rule
Rules to optimize performance of React and TypeScript components.
nextjs
Next.js 16 App Router Standards & Constraints.