This repository was archived by the owner on Feb 14, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d4f43f5
commit 4c49c94
Showing
9 changed files
with
82 additions
and
392 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,23 @@ | ||
import { usePathname, useRouter, useSearchParams } from "next/navigation"; | ||
import { | ||
useObserveAndStore as useObserveAndStoreReact, | ||
type SupportedValues, | ||
} from "@sp-hooks/react"; | ||
import { usePathname, useRouter } from "next/navigation"; | ||
|
||
// export const useSearchParamsState = < | ||
// S extends Partial<Record<string, string | string[]>>, | ||
// >( | ||
// opts?: UseSearchParamsStateOptions<S>, | ||
// ) => { | ||
// const searchParams = useSearchParams(); | ||
// const router = useRouter(); | ||
// const pathname = usePathname(); | ||
import { useObserveAndStore as useObserveAndStoreReact } from "@sp-hooks/react"; | ||
import type { SPHooksStateType } from "@sp-hooks/react"; | ||
|
||
// const setSearchParams = (newSearchParams: URLSearchParams) => { | ||
// router.push(pathname + "?" + newSearchParams.toString()); | ||
// }; | ||
export * from "@sp-hooks/react"; | ||
export type * from "@sp-hooks/react"; | ||
|
||
// return useSearchParamsStateReact<S>({ | ||
// searchParams, | ||
// setSearchParams, | ||
// ...opts, | ||
// }); | ||
// }; | ||
|
||
export function useObserveAndStore<S extends Record<string, SupportedValues>>( | ||
export function useObserveAndStore<S extends SPHooksStateType>( | ||
state: S, | ||
options?: { defaultValues?: Partial<S> }, | ||
) { | ||
const router = useRouter(); | ||
const pathname = usePathname(); | ||
|
||
useObserveAndStoreReact(state, (newSearchParams) => { | ||
router.push(pathname + "?" + newSearchParams.toString()); | ||
}); | ||
useObserveAndStoreReact( | ||
state, | ||
(newSearchParams) => { | ||
router.push(pathname + "?" + newSearchParams.toString()); | ||
}, | ||
options, | ||
); | ||
} |
Oops, something went wrong.