File size: 749 Bytes
a72140d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"use client";

import React, { createContext, useContext, ReactNode } from "react";

type SearchParamsContextType = { [key: string]: string | string[] | undefined };

const SearchParamsContext = createContext<SearchParamsContextType | null>(null);

export const SearchParamsProvider = ({
  children,
  params,
}: {
  children: ReactNode;
  params: SearchParamsContextType;
}) => {
  return (
    <SearchParamsContext.Provider value={params}>
      {children}
    </SearchParamsContext.Provider>
  );
};

export const useSearchParamsContext = () => {
  const context = useContext(SearchParamsContext);

  if (!context) {
    throw new Error(
      "useSearchParamsContext must be used within a SearchParamsProvider",
    );
  }

  return context;
};