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:
Yassine 2025-04-11 20:25:05 +01:00 committed by GitHub
commit f9bd4b81cc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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({