T
TanStack4mo ago
like-gold

How to achieve type safety in this scenario?

I have the following routes: /route/$id/tab1 /route/$id/tab2 /route/$id/tab3 I have the following hook: const tabs = ['tab1', 'tab2', tab3'] as const; export function useCurrentTab() { const currentTab = useRouterState({ select: (state) => state.location.pathname.split('/').at(-1), }) as (typeof tabs)[number] | undefined; return [currentTab && tabs.includes(currentTab) ? currentTab : tabs[0], tabs] as const; } I want to avoid casting the current tab to as (typeof tabs)[number] | undefined;
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?