create-brainerce-store 1.28.17 → 1.28.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  <% if (i18nEnabled) { %>
2
2
  'use client';
3
3
 
4
- import React from 'react';
4
+ import React, { useMemo, useCallback } from 'react';
5
5
  import NextLink from 'next/link';
6
6
  import { useRouter as useNextRouter, usePathname } from 'next/navigation';
7
7
  import type { ComponentProps } from 'react';
@@ -48,21 +48,32 @@ export function Link({ href, ...props }: ComponentProps<typeof NextLink>) {
48
48
 
49
49
  /**
50
50
  * Locale-aware useRouter — push/replace automatically prepend locale.
51
+ * Returns a stable reference to avoid infinite re-render loops when used
52
+ * in useEffect dependency arrays.
51
53
  */
52
54
  export function useRouter() {
53
55
  const router = useNextRouter();
54
56
  const pathname = usePathname();
55
57
  const locale = getLocale(pathname);
56
58
 
57
- return {
58
- ...router,
59
- push: (url: string, options?: Parameters<typeof router.push>[1]) => {
59
+ const push = useCallback(
60
+ (url: string, options?: Parameters<typeof router.push>[1]) => {
60
61
  return router.push(localizePath(url, locale), options);
61
62
  },
62
- replace: (url: string, options?: Parameters<typeof router.replace>[1]) => {
63
+ [router, locale]
64
+ );
65
+
66
+ const replace = useCallback(
67
+ (url: string, options?: Parameters<typeof router.replace>[1]) => {
63
68
  return router.replace(localizePath(url, locale), options);
64
69
  },
65
- };
70
+ [router, locale]
71
+ );
72
+
73
+ return useMemo(
74
+ () => ({ ...router, push, replace }),
75
+ [router, push, replace]
76
+ );
66
77
  }
67
78
  <% } else { %>
68
79
  /* Single-language store — re-export Next.js navigation as-is */