You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Originally posted by ryanflorence November 23, 2024
Right now you access active, pending, and transitioning states from a bunch of different hooks. This proposal hopes to consolidate them all into a simpler API.
letnavigation=useNavigation()navigation.location// have to construct search paramsletsearchParams=newURLSearchParams(navigation.location.search,)// no accessletparams=undefinedlettype=undefined// access to form stuff (rarely used, fetchers usually better)navigation.formAction// etc.
All of those hooks are either accessing active/pending states or matching against a path and providing active/pending states. We can do this with one hook.
typeRouterStateVariant={location: LocationsearchParams: URLSearchParamsparams: Paramsmatches: Matches}typeRouterState={active: RouterStateVariantpending: null|RouterStateVarianttransitioning: boolean}let{ active, pending, transitioning }=useRouterState()// user clicks a link, both active and pending could have valuesactive.locationpending.location
By providing a path to the hook, we can match against it to determine the states, and even provide better types
typeRouterStateVariant<Path>={location: Location<Path>searchParams: URLSearchParams<Path>params: Params<Path>matches: Matches<Path>type: NavigationType// Pop, Push, Replace}typeRouterState<Path>={active: null|RouterStateVariant<Path>pending: null|RouterStateVariant<Path>transitioning: boolean}let{ active, pending, transitioning }=useRouterState('/projects/:id')// the url is /projects/123active.params.idactive.location// etc.pending===null// the url is /projects, user clicked /projects/123active===nullpending.params.idpending.location
Deprecations
This one hook can deprecate all eight of these:
useLocation
useSearchParams
useParams
useTransitionState
useNavigation
useMatches
useMatch(pattern)
useNavigationType
Refactor
Probably some potential refactoring to simplify the code and have the deprecated hooks (and NavLink) use the new hook underneath.
The text was updated successfully, but these errors were encountered:
Discussed in #12358
Originally posted by ryanflorence November 23, 2024
Right now you access active, pending, and transitioning states from a bunch of different hooks. This proposal hopes to consolidate them all into a simpler API.
Today
Accessing Current States
Accessing Pending States
Accessing View Transition States
Proposal: Consolidate into one hook
All of those hooks are either accessing active/pending states or matching against a path and providing active/pending states. We can do this with one hook.
By providing a path to the hook, we can match against it to determine the states, and even provide better types
Deprecations
This one hook can deprecate all eight of these:
useLocation
useSearchParams
useParams
useTransitionState
useNavigation
useMatches
useMatch(pattern)
useNavigationType
Refactor
Probably some potential refactoring to simplify the code and have the deprecated hooks (and NavLink) use the new hook underneath.
The text was updated successfully, but these errors were encountered: