Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move locale switching logic out of state
- Loading branch information
1 parent
f87b369
commit 3b25c9a
Showing
4 changed files
with
25 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@makeswift/runtime': patch | ||
--- | ||
|
||
Moves locale switching logic out of the redux middleware state and closer to Next.js logic. |
16 changes: 16 additions & 0 deletions
16
packages/runtime/src/components/hooks/useRouterLocaleSync.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { useRouter } from 'next/router' | ||
|
||
import { useEffect } from 'react' | ||
import { setLocale } from '../../state/actions' | ||
import { useDispatch } from '../../runtimes/react/hooks/use-dispatch' | ||
|
||
export const useRouterLocaleSync = () => { | ||
const router = useRouter() | ||
const dispatch = useDispatch() | ||
|
||
useEffect(() => { | ||
if (!router.locale) return | ||
|
||
dispatch(setLocale(new Intl.Locale(router.locale))) | ||
}, [router.locale]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters