Knowledgebase

State Management: Everything That Matters, Briefly Print

  • frontenddevelopment, frontend, woocommerce, caching, guide, howto, solution, zillionkinghost
  • 0

The summary.

MOST APPLICATIONS HAVE FAR LESS SHARED STATE THAN ASSUMED

Most of what ends up in a global store is server data or address state.

Ask what genuinely needs sharing, and how often it changes, before adding a library.

SERVER DATA IS A CACHE, NOT STATE YOU OWN

Use a library built for it: caching, deduplication, background refetching, invalidation after mutations.

That removes the majority of the code people write around fetching.

PUT FILTERS, SEARCH AND PAGINATION IN THE ADDRESS

Users expect to share a link to what they are looking at.

ONE SOURCE OF TRUTH FOR EACH PIECE OF DATA

Never duplicate it, and never store derived values — compute them.

CONTEXT AND PROVIDE FACILITIES ARE FOR VALUES THAT CHANGE RARELY

Frequently changing values re-render everything consuming them.

A SHARED STORE ON A SERVER LEAKS DATA BETWEEN USERS

Check how any library handles server rendering before using it there.

SELECT NARROWLY, SO COMPONENTS RE-RENDER ONLY WHEN WHAT THEY USE CHANGES


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot