Skip to content

Commit

Permalink
Exported useHistorySubscription
Browse files Browse the repository at this point in the history
  • Loading branch information
smikhalevski committed Jul 8, 2024
1 parent 2934470 commit 8ba405b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/main/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
10 changes: 9 additions & 1 deletion src/main/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down

0 comments on commit 8ba405b

Please sign in to comment.