agentleFS
hi-donwihi-donwi/Donwi-Skills/skills/frontend-state/SKILL.md

frontend-state

Skill0 starsChanged 12 days agoMITView on GitHub

Decide where frontend state belongs: local, lifted, URL search params, server cache, or global store. Use when components re-render or props drill excessively.

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Ask whether it is state at all: If it can be computed from props, existing state, or the URL, compute it.

    line 37

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Frontend State

Overview

Where state lives decides more about a frontend's future than any other choice. Put it too low and it gets lifted, drilled and duplicated; put it too high and every unrelated change re-renders the app. Most frontends described as spaghetti are not badly written — they are holding one fact in three places.

When to use

  • Choosing between useState, lifted state, context, a URL param, a query cache, a store
  • The same fact exists in more than one place and they disagree
  • Props passed through components that do not use them
  • A component re-renders on changes it does not care about
  • Server data kept in a global store and manually refreshed
  • A refresh, a shared link, or the back button loses the user's place

Hand off when

NeedSkill
Splitting the component, file layoutfrontend-ui-engineering
Field state, validation, submit lifecycleforms-and-validation
The request and response contractapi-design
Measuring a render problem before fixing itweb-perf

Process

  1. Ask whether it is state at all. If it can be computed from props, existing state, or the URL, compute it. Stored derived values are the most common source of two sources of truth disagreeing.
  2. Separate server data from client state. They have different lifecycles: server data is a cache of something you do not own, with staleness, refetching and invalidation. Client state is yours. Putting server data in a global store means reimplementing a cache by hand, badly.
  3. Climb the ladder only as far as needed. Local → lifted → URL → server cache → context → store. Each rung costs coupling; stop at the first that works.
  4. Put shareable state in the URL. Filters, tabs, pagination, the open item. If a user should be able to send the link, refresh, or press back, the URL is the store — and it is free.
  5. Use context for read-heavy, write-rare values — theme, locale, current user. Context is a dependency-injection mechanism, not a state manager: every consumer re-renders on every change.
  6. Reach for a global store last, and only for genuinely app-wide client state that several distant trees both read and write.
  7. Keep state minimal and normalised. Store ids, not copies of objects that also live in the cache. Two copies drift the moment one is updated.
  8. Co-locate. State used by one subtree lives in that subtree. Lifting to the root "so it is available" is how a root component acquires forty fields.

Red flags

  • useEffect that copies a prop into state, then tries to keep them in sync
  • Server data in Redux/Zustand with hand-rolled loading and error flags
  • Filters or the active tab in component state, so the URL is unshareable
  • Context holding a value that changes on every keystroke
  • A store slice one component reads and nothing else
  • Props threaded through three components that only pass them along
  • Derived values stored and recomputed in an effect instead of during render
  • useMemo/useCallback added before anything was measured
  • State lifted to the root because two leaves needed it
  • The same entity held in a list and again in a "selected" object

Verification

  • Every piece of state has one owner and one source of truth
  • Derived values are computed, not stored
  • Server data lives in a cache with invalidation, not in a client store
  • Shareable UI state survives refresh, back, and copying the link
  • No effect exists purely to synchronise two pieces of state
  • Context values are stable, or split so a change wakes only its consumers
  • Changing one feature's state does not re-render unrelated trees
  • No prop passes through a component that does not read it

References

  • references/the-ladder.md — each rung, what it is for, and the cost of the next one
  • references/server-vs-client.md — cache semantics, and why server data is not app state
  • references/untangling.md — diagnosing duplicated state, sync effects, and drilling

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.