From 8ba405b411c25d627bac3a6071eedb41a8185fbe Mon Sep 17 00:00:00 2001 From: smikhalevski Date: Tue, 9 Jul 2024 01:04:19 +0300 Subject: [PATCH] Exported useHistorySubscription --- README.md | 2 ++ src/main/hooks.ts | 5 +++++ src/main/index.ts | 10 +++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f72342e..7fe2120 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,8 @@ npm install --save-prod react-corsair ``` +🔥 [**Live example**](https://codesandbox.io/p/sandbox/react-corsair-example-mzjzcm) + # Introduction React Corsair is a router that abstracts URLs away from the domain of your application. It doesn't depend on diff --git a/src/main/hooks.ts b/src/main/hooks.ts index 4e17190..9a6ac80 100644 --- a/src/main/hooks.ts +++ b/src/main/hooks.ts @@ -6,6 +6,11 @@ import { Route } from './Route'; import { NavigationContext } from './Router'; import { History, Location } from './types'; +/** + * Subscribes component to updates of a history adapter and triggers re-render when history location is changed. + * + * @param history The history to subscribe to. + */ export function useHistorySubscription(history: History): void { useSyncExternalStore(history.subscribe, () => history.location); } diff --git a/src/main/index.ts b/src/main/index.ts index 5885859..0d47b11 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -1,7 +1,15 @@ export { createBrowserHistory } from './createBrowserHistory'; export { createMemoryHistory } from './createMemoryHistory'; export { createRoute } from './createRoute'; -export { useNavigation, useLocation, useRoute, useRouteData, useRouteParams, useRouteError } from './hooks'; +export { + useHistorySubscription, + useNavigation, + useLocation, + useRoute, + useRouteData, + useRouteParams, + useRouteError, +} from './hooks'; export { Link } from './Link'; export { Navigation } from './Navigation'; export { notFound, NotFoundError } from './notFound';