mirror of
https://github.com/Kong/insomnia
synced 2024-11-12 17:26:32 +00:00
28 lines
717 B
TypeScript
28 lines
717 B
TypeScript
import React, { createContext, FC, useContext } from 'react';
|
|
|
|
interface Props {
|
|
disable?: boolean;
|
|
}
|
|
|
|
interface NunjucksEnabledState {
|
|
enabled: boolean;
|
|
}
|
|
|
|
const NunjucksEnabledContext = createContext<NunjucksEnabledState | undefined>(undefined);
|
|
|
|
export const NunjucksEnabledProvider: FC<Props> = ({ disable, children }) => (
|
|
<NunjucksEnabledContext.Provider value={{ enabled: !disable }}>
|
|
{children}
|
|
</NunjucksEnabledContext.Provider>
|
|
);
|
|
|
|
export const useNunjucksEnabled = () => {
|
|
const context = useContext(NunjucksEnabledContext);
|
|
|
|
if (context === undefined) {
|
|
throw new Error('useNunjucksEnabled must be used within a NunjucksEnabledProvider or NunjucksProvider');
|
|
}
|
|
|
|
return context;
|
|
};
|