BlueWallet/components/react-native-draggable-flatlist/context/cellContext.tsx

31 lines
689 B
TypeScript
Raw Normal View History

2022-01-26 10:54:32 -05:00
import React, { useContext, useMemo } from 'react';
type CellContextValue = {
isActive: boolean;
};
const CellContext = React.createContext<CellContextValue | undefined>(undefined);
type Props = {
isActive: boolean;
children: React.ReactNode;
};
export default function CellProvider({ isActive, children }: Props) {
const value = useMemo(
() => ({
isActive,
}),
[isActive],
);
return <CellContext.Provider value={value}>{children}</CellContext.Provider>;
}
export function useIsActive() {
const value = useContext(CellContext);
if (!value) {
throw new Error('useIsActive must be called from within CellProvider!');
}
return value.isActive;
}