import {createSearchContext, useSearchContextReducer} from '@hooks';
import {ChildrenFC} from '@utils';

type Props = {
  context: ReturnType<typeof createSearchContext>;
  preloadKey?: string;
};

const SearchProvider: ChildrenFC<Props> = function ({
  children,
  context,
  preloadKey,
}) {
  const {Provider} = context;
  const state = useSearchContextReducer(preloadKey);

  return <Provider value={state}>{children}</Provider>;
};

export default SearchProvider;
