State

state/url-state

State a person would share, bookmark or restore with Back (filters, sort, page, selected tab, search) lives in the URL.

minormanualfe-state

Why

Filters and pagination kept in component or store state are lost on reload, cannot be shared as a link, and the Back button leaves the page instead of undoing the last filter. Server rendering also cannot see them, so the first paint shows the unfiltered list.

Fix

Read these values from the search params (useSearchParams, page.url.searchParams, useRoute().query, ActivatedRoute.queryParamMap) and change them by navigating (router.replace for typing, push for deliberate steps). Keep throwaway UI state (an open menu, hover) in component state.

Examples

// bad
const [sort, setSort] = useState('price')
// good
const params = useSearchParams()
const sort = params.get('sort') ?? 'price'

Sources

Facts

Id
state/url-state
Severity
minor
Check
manual a person reviews it; the report lists it as a checklist
Applies to
jsx vue svelte angular
Taught by the skill
fe-state State and stores
Since version
0.1.0

Rule file on GitHub

Read it in the terminal

npx github:dawidolko/frontend-skills explain state/url-state