Skip to content

Commit 4d35094

Browse files
committed
feat: router provider 추가
1 parent 10e3e82 commit 4d35094

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { RouterInstance } from "@hanghae-plus/lib";
2+
import type { FC, PropsWithChildren } from "react";
3+
4+
import { RouterContext } from "./hooks";
5+
6+
type RouterProviderProps = PropsWithChildren<{
7+
router: RouterInstance<FC>;
8+
}>;
9+
10+
export function RouterProvider({ children, router }: RouterProviderProps) {
11+
return <RouterContext value={router}>{children}</RouterContext>;
12+
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
export * from "./useRouterQuery";
2-
export * from "./useRouterParams";
31
export * from "./useCurrentPage";
2+
export * from "./useRouterContext";
3+
export * from "./useRouterParams";
4+
export * from "./useRouterQuery";
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { RouterInstance } from "@hanghae-plus/lib";
2+
import { createContext, useContext, type FC } from "react";
3+
4+
export const RouterContext = createContext<RouterInstance<FC> | null>(null);
5+
6+
export const useRouterContext = () => {
7+
const router = useContext(RouterContext);
8+
9+
if (!router) {
10+
throw new Error("Router context not found");
11+
}
12+
13+
return router;
14+
};

packages/react/src/router/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
export * from "./router";
21
export * from "./hooks";
2+
export * from "./router";
3+
export * from "./RouterProvider";

0 commit comments

Comments
 (0)