refactor: flatten routes
This commit is contained in:
14
app/hooks/useMatch.ts
Normal file
14
app/hooks/useMatch.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { useMatches } from "@remix-run/react";
|
||||
|
||||
export function useMatch() {
|
||||
const matches = useMatches();
|
||||
const { handle, ...rest } = matches[matches.length - 1];
|
||||
|
||||
if (handle == null) {
|
||||
throw new Error("Bruh");
|
||||
}
|
||||
|
||||
return { handle, ...rest } as unknown as {
|
||||
handle: { to: string; text: string };
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user