mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
Merge pull request #912 from Hexastack/911-issue---useblock-outside-provider
fix: add exception when useBlock is outside the block provider
This commit is contained in:
commit
f9bd4b81cc
@ -15,7 +15,15 @@ import { IBlock, IBlockAttributes } from "@/types/block.types";
|
||||
const BlockContext = createContext<IBlock | undefined>(undefined);
|
||||
|
||||
// Custom hook to use block context
|
||||
export const useBlock = () => useContext(BlockContext);
|
||||
export const useBlock = () => {
|
||||
const context = useContext(BlockContext);
|
||||
|
||||
if (!context) {
|
||||
throw new Error("useBlock must be used within an BlockContext");
|
||||
}
|
||||
|
||||
return context;
|
||||
};
|
||||
|
||||
// This component wraps FormProvider and adds block to its context
|
||||
function BlockFormProvider({
|
||||
|
Loading…
Reference in New Issue
Block a user