change
This commit is contained in:
14
src/shared/hooks/use-locale.ts
Normal file
14
src/shared/hooks/use-locale.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
export const useLocale = ()=>{
|
||||
const locale = window.location.pathname.split('/')[1]
|
||||
const setLocale = (newLocale: string) => {
|
||||
const segments = window.location.pathname.split('/');
|
||||
segments[1] = newLocale;
|
||||
const newPath = segments.join('/');
|
||||
window.history.pushState({}, '', newPath);
|
||||
window.location.reload();
|
||||
}
|
||||
return {
|
||||
locale,
|
||||
setLocale
|
||||
}
|
||||
}
|
||||
19
src/shared/hooks/use-mobile.ts
Normal file
19
src/shared/hooks/use-mobile.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import * as React from "react"
|
||||
|
||||
const MOBILE_BREAKPOINT = 768
|
||||
|
||||
export function useIsMobile() {
|
||||
const [isMobile, setIsMobile] = React.useState<boolean | undefined>(undefined)
|
||||
|
||||
React.useEffect(() => {
|
||||
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`)
|
||||
const onChange = () => {
|
||||
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
|
||||
}
|
||||
mql.addEventListener("change", onChange)
|
||||
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
|
||||
return () => mql.removeEventListener("change", onChange)
|
||||
}, [])
|
||||
|
||||
return !!isMobile
|
||||
}
|
||||
27
src/shared/hooks/use-query-string.ts
Normal file
27
src/shared/hooks/use-query-string.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
'use client';
|
||||
|
||||
import { useSearchParams, useRouter, usePathname } from 'next/navigation';
|
||||
import { useCallback } from 'react';
|
||||
|
||||
export function useQueryString() {
|
||||
const searchParams = useSearchParams();
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
|
||||
const createQueryString = useCallback(
|
||||
(name: string, value: string) => {
|
||||
const params = new URLSearchParams(searchParams.toString());
|
||||
params.set(name, value);
|
||||
|
||||
return params.toString();
|
||||
},
|
||||
[searchParams]
|
||||
);
|
||||
|
||||
return {
|
||||
searchParams,
|
||||
router,
|
||||
pathname,
|
||||
createQueryString,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user