Add warning when deleting options with votes

This commit is contained in:
Luke Vella 2022-04-15 18:08:28 +01:00
parent ae9d9f1083
commit 654c300430
7 changed files with 150 additions and 20 deletions

View file

@ -0,0 +1,14 @@
import React from "react";
export const useRequiredContext = <T extends any>(
context: React.Context<T | null>,
errorMessage?: string,
) => {
const contextValue = React.useContext(context);
if (contextValue === null) {
throw new Error(
errorMessage ?? `Missing context provider: ${context.displayName}`,
);
}
return contextValue;
};