@0xsequence/connect
Version:
Connect package for Sequence Web SDK
16 lines • 762 B
JavaScript
import { createContext, useContext } from 'react';
// https://medium.com/@rivoltafilippo/typing-react-context-to-avoid-an-undefined-default-value-2c7c5a7d5947
export const createGenericContext = () => {
// Create a context with a generic parameter or undefined
const genericContext = createContext(undefined);
// Check if the value provided to the context is defined or throw an error
const useGenericContext = () => {
const contextIsDefined = useContext(genericContext);
if (!contextIsDefined) {
throw new Error('useGenericContext must be used within a Provider');
}
return contextIsDefined;
};
return [useGenericContext, genericContext.Provider];
};
//# sourceMappingURL=genericContext.js.map