18 lines
614 B
TypeScript
18 lines
614 B
TypeScript
'use client';
|
|
|
|
import { createContext, type PropsWithChildren, useMemo, useState } from 'react';
|
|
|
|
export type FilterType = 'all' | 'clients' | 'masters';
|
|
|
|
type ContextType = { filter: FilterType; setFilter: (filter: FilterType) => void };
|
|
|
|
export const ContactsContext = createContext<ContextType>({} as ContextType);
|
|
|
|
export function ContactsContextProvider({ children }: Readonly<PropsWithChildren>) {
|
|
const [filter, setFilter] = useState<FilterType>('all');
|
|
|
|
const value = useMemo(() => ({ filter, setFilter }), [filter, setFilter]);
|
|
|
|
return <ContactsContext value={value}>{children}</ContactsContext>;
|
|
}
|