Skip to content

Commit

Permalink
feat: displayName and expose history listen
Browse files Browse the repository at this point in the history
  • Loading branch information
erictaylor committed Aug 31, 2021
1 parent 54d2688 commit 7eb8b53
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/components/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,5 @@ export const Link = forwardRef(
);
}
);

Link.displayName = 'Link';
2 changes: 2 additions & 0 deletions src/components/RouteRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,5 @@ export const RouteRenderer = ({
</>
);
};

RouteRenderer.displayName = 'RouteRenderer';
2 changes: 2 additions & 0 deletions src/components/RouterProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ export const RouterProvider = ({ children, router }: RouterProviderProps) => {
<RouterContext.Provider value={router}>{children}</RouterContext.Provider>
);
};

RouterProvider.displayName = 'RouterProvider';
2 changes: 2 additions & 0 deletions src/hooks/__tests__/useHistory.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const ContextWrapper = ({ children }: { children: ReactNode }) => {
{
history: {
action: 'mockHistoryAction',
listen: 'mockHistoryListen',
location: 'mockHistoryLocation',
},
} as unknown as RouterContextProps
Expand All @@ -37,6 +38,7 @@ describe('useHistory()', () => {

expect(result.current).toEqual({
action: 'mockHistoryAction',
listen: 'mockHistoryListen',
location: 'mockHistoryLocation',
});
});
Expand Down
9 changes: 6 additions & 3 deletions src/hooks/useHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { useContext } from 'react';
import { isRouterContext, RouterContext } from '../context/RouterContext';
import type { RouterContextProps } from '../types';

type UseHistory<S extends State> = Pick<History<S>, 'action' | 'location'>;
type UseHistory<S extends State> = Pick<
History<S>,
'action' | 'listen' | 'location'
>;

export const useHistory = <S extends State = State>(): UseHistory<S> => {
const context = useContext(RouterContext) as RouterContextProps<S>;
Expand All @@ -14,7 +17,7 @@ export const useHistory = <S extends State = State>(): UseHistory<S> => {
);
}

const { action, location } = context.history;
const { action, listen, location } = context.history;

return { action, location };
return { action, listen, location };
};

0 comments on commit 7eb8b53

Please sign in to comment.