Stan aplikacji

state/url-state

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

drobnaręcznefe-state

Dlaczego

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.

Poprawka

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.

Przykłady

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

Źródła

Fakty

Identyfikator
state/url-state
Waga
drobna
Sprawdzanie
ręczne ocenia człowiek; raport podaje to jako listę kontrolną
Dotyczy plików
jsx vue svelte angular
Uczy jej skill
fe-state State and stores
Od wersji
0.1.0

Plik reguły na GitHubie

Przeczytaj w terminalu

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