UNPKG

opencode-agent-kit

Version:

Multi-stack OpenCode agent toolkit — 33+ specialized AI agents, 200+ skills, 46 commands, 8 MCP servers (Nuxt, React, Node.js, Laravel, CI3, Android, Flutter, DevOps, SEO, SonarQube, and more)

36 lines (27 loc) 1.02 kB
--- title: Do not wrap a simple expression with a primitive result type in useMemo impact: LOW-MEDIUM impactDescription: wasted computation on every render tags: rerender, useMemo, optimization --- ## Do not wrap a simple expression with a primitive result type in useMemo When an expression is simple (few logical or arithmetical operators) and has a primitive result type (boolean, number, string), do not wrap it in `useMemo`. Calling `useMemo` and comparing hook dependencies may consume more resources than the expression itself. **Incorrect:** ```tsx function Header({ user, notifications }: Props) { const isLoading = useMemo(() => { return user.isLoading || notifications.isLoading }, [user.isLoading, notifications.isLoading]) if (isLoading) return <Skeleton /> // return some markup } ``` **Correct:** ```tsx function Header({ user, notifications }: Props) { const isLoading = user.isLoading || notifications.isLoading if (isLoading) return <Skeleton /> // return some markup } ```