1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 12:56:41 +07:00

moved search provider to the top of the app

This commit is contained in:
Fedor Katurov 2022-01-04 15:54:40 +07:00
parent 31fc033d4f
commit 7dfa6f89c7
4 changed files with 13 additions and 12 deletions

View file

@ -1,42 +0,0 @@
import React, { createContext, FC, useContext } from 'react';
import { INode } from '~/redux/types';
import { useSearch } from '~/hooks/search/useSearch';
export interface SearchContextProps {
searchText: string;
hasMore: boolean;
searchIsLoading: boolean;
searchResults: INode[];
setSearchText: (text: string) => void;
loadMore: () => void;
}
export const SearchContext = createContext<SearchContextProps>({
searchText: '',
hasMore: false,
searchIsLoading: false,
searchResults: [],
setSearchText: () => {},
loadMore: () => {},
});
export const SearchContextProvider: FC = ({ children }) => {
const { results, searchText, isLoading, loadMore, setSearchText, hasMore } = useSearch();
return (
<SearchContext.Provider
value={{
searchText,
searchResults: results,
searchIsLoading: isLoading,
hasMore,
setSearchText,
loadMore,
}}
>
{children}
</SearchContext.Provider>
);
};
export const useSearchContext = () => useContext(SearchContext);