mirror of
https://github.com/lukevella/rallly.git
synced 2025-07-16 07:55:29 +02:00
Add warning when deleting options with votes
This commit is contained in:
parent
ae9d9f1083
commit
654c300430
7 changed files with 150 additions and 20 deletions
14
components/use-required-context.ts
Normal file
14
components/use-required-context.ts
Normal 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;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue