Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(react): export stable router reference for useIonRouter hook #25000

Merged
20 changes: 12 additions & 8 deletions packages/react/src/components/IonRouterContext.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AnimationBuilder } from '@ionic/core/components';
import React, { useContext } from 'react';
import React, { useContext, useMemo } from 'react';

import { RouteAction, RouterDirection, RouterOptions } from '../models';
import { RouteInfo } from '../models/RouteInfo';
Expand Down Expand Up @@ -39,13 +39,17 @@ export const IonRouterContext = React.createContext<IonRouterContextState>({
*/
export function useIonRouter(): UseIonRouterResult {
const context = useContext(IonRouterContext);
return {
back: context.back,
push: context.push,
goBack: context.back,
canGoBack: context.canGoBack,
routeInfo: context.routeInfo,
};

return useMemo(
() => ({
back: context.back,
push: context.push,
goBack: context.back,
canGoBack: context.canGoBack,
routeInfo: context.routeInfo,
}),
[context.back, context.push, context.canGoBack, context.routeInfo]
);
}

export type UseIonRouterResult = {
Expand Down