diff --git a/src/context.ts b/src/context.ts index 04ed578..03c242d 100644 --- a/src/context.ts +++ b/src/context.ts @@ -8,6 +8,7 @@ export interface SharedFlexContext { requestReflow(): void registerBox(node: YogaNode, group: Group, flexProps: R3FlexProps, centerAnchor?: boolean): void unregisterBox(node: YogaNode): void + notInitialized?: boolean } const initialSharedFlexContext: SharedFlexContext = { @@ -21,6 +22,7 @@ const initialSharedFlexContext: SharedFlexContext = { unregisterBox() { console.warn('Flex not initialized! Please report') }, + notInitialized: true, } export const flexContext = createContext(initialSharedFlexContext) @@ -29,11 +31,13 @@ export interface SharedBoxContext { node: YogaNode | null size: [number, number] centerAnchor?: boolean + notInitialized?: boolean } const initialSharedBoxContext: SharedBoxContext = { node: null, size: [0, 0], + notInitialized: true, } export const boxContext = createContext(initialSharedBoxContext) diff --git a/src/hooks.ts b/src/hooks.ts index 17ded20..79ae372 100644 --- a/src/hooks.ts +++ b/src/hooks.ts @@ -2,9 +2,9 @@ import { useCallback, useContext as useContextImpl, useMemo } from 'react' import { Mesh, Vector3 } from 'three' import { flexContext, boxContext } from './context' -export function useContext(context: React.Context) { +export function useContext(context: React.Context) { let result = useContextImpl(context) - if (!result) { + if (result.notInitialized) { console.warn('You must place this hook/component under a component!') } return result