October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

React AI Rule Files: What to Put in the State Section

A useful React state rule changes the code an AI assistant produces. These six project conventions define practical choices without confusing them with official React requirements.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A state rule belongs in a React project’s AI instructions when it changes the code an assistant produces for a concrete feature. Avery, author of a DEV Community article on the subject, puts the test this way: “A rule belongs in the file if a session that reads it produces different code than a session that does not.” Use the state section to set project-specific decision boundaries—not to repeat general advice such as “keep state in the right place.”

Start with a rule that changes implementation choices

“Keep state in the right place” sounds sensible but does not tell an assistant what to do. A useful instruction gives it a decision it can apply while building a feature: which component or feature owns a value, when values should be derived rather than stored, and how asynchronous states should be represented.

As an Amazon Associate I earn from qualifying purchases.

Avery’s six examples below are project conventions, not requirements imposed by React. React’s documentation supports several underlying practices, including avoiding redundant state and treating state as immutable, but it does not mandate Avery’s exact thresholds or component boundaries.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Six state rules to consider for a React project

1. Keep state local until independent features need it

Avery’s convention is to keep state within a feature or screen unless at least two independent features need it over the long term. Two components in the same feature do not, by themselves, meet that threshold; they may simply need a shared owner within that feature. Authentication state is not automatically global under this convention either: decide based on which independent features need it and for how long.

This is a project decision boundary, not a React rule. React’s state-management guidance describes lifting state to a common owner when components need to coordinate. For values needed farther down a tree, context is another option; it is not a reason to make every value global.

2. Keep one mutable owner for the same domain data

Do not maintain multiple mutable copies of the same information as competing sources of truth. If a feature needs the original value for comparison, treat it as a comparison snapshot rather than a second current value that can drift out of sync.

This convention aligns with React’s guidance to avoid redundant state. When the same fact is stored in multiple places, updates can leave the copies inconsistent.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

3. Derive values instead of storing them

Do not store values that can be calculated from existing props or state, including dirty flags and comparison results. Calculate them during render so they cannot fall out of sync with their inputs.

For example, compute whether a form differs from its initial values from the current and initial values rather than updating a separate isDirty state variable. React’s guidance on structuring state explains why redundant state creates opportunities for mismatches.

4. Do not use an effect for synchronous derivation

If a value can be calculated synchronously from props or state, calculate it during render instead of copying it into state and synchronizing it with an effect. This rule is about derivation, not a ban on effects: effects remain appropriate for synchronizing with external systems and other work that belongs outside rendering.

5. Represent asynchronous outcomes explicitly when types allow

In a typed project, model loading, error, and success as explicit states when the application’s types support that representation. Avoid making null stand for several unrelated conditions, such as “not loaded yet,” “request failed,” or “there is no result.”

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

This is a project convention for making states and their handling clear; it is not a requirement of React’s API.

6. Separate form presentation from state transformation when it helps reuse

Avery’s convention keeps the form component focused on presentation, supplies initial values from outside, and puts state transformation in a hook. This can make the boundary easier to reuse and test in a project that benefits from that separation. It is a design choice, not a React-prescribed form architecture.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Update object state without mutating it

React’s documentation says: “Props and state are immutable snapshots with respect to a single render. Never mutate them directly.” When updating an object in state, create a replacement object and pass it to the setter rather than changing the existing object in place. React’s object-state guidance also emphasizes that object spread makes a shallow copy: nested objects still need to be copied along the path being updated.

This is official React guidance, unlike the project-specific thresholds and form boundary above. The current React documentation identifies itself as React v19.3.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Check whether the rules change generated code

Use Avery’s proposed exercise as a practical check, not as a controlled study: take a recently generated component and give the same feature prompt to an AI coding assistant twice, once with the six rules and once without them. Compare the implementation choices that the rules are meant to affect:

  • Where the state lives and whether the features using it are independent.
  • Whether values derivable from props or state are stored separately.
  • Whether two locations own mutable copies of the same information.
  • How loading, error, and success are represented.

If the outputs are effectively unchanged, sharpen the project’s decision conditions before adding more rules. Avery describes the sample section as around two hundred words; that is a description of the example, not evidence that a particular length or rule file improves results. The cited article and React documentation do not establish a named study or statistic measuring the effectiveness of these instructions.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.