Skip to content

Commit feb2a37

Browse files
committed
fix: useXRInputSourceStateContext can only be used inside the xr store config
1 parent c49cf88 commit feb2a37

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

packages/react/xr/src/input.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,13 @@ export function useXRInputSourceStateContext<T extends keyof XRInputSourceStateM
3636
type?: T,
3737
): XRInputSourceStateMap[T] {
3838
const state = useContext(xrInputSourceStateContext)
39-
if (state == null || (type != null && state.type != type)) {
40-
throw new Error(`useXRInputSourceStateContext() can only be used inside a the xr store config`)
39+
if (state == null) {
40+
throw new Error(`useXRInputSourceStateContext() can only be used inside the xr store config`)
41+
}
42+
if (type != null && state.type != type) {
43+
throw new Error(
44+
`useXRInputSourceStateContext(${type}) can not be used inside a component for input type "${state.type}"`,
45+
)
4146
}
4247
return state as XRInputSourceStateMap[T]
4348
}

packages/react/xr/src/space.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const XRSpace = forwardRef<
2929
>(({ space, children }, ref) => {
3030
const internalRef = useRef<Group | null>(null)
3131
// eslint-disable-next-line react-hooks/rules-of-hooks
32-
const resolvedSpace = useXRSpace(space as any)
32+
const resolvedSpace = typeof space === 'string' ? useXRSpace(space) : space
3333
useImperativeHandle(ref, () => internalRef.current!, [])
3434
useApplyXRSpaceMatrix(internalRef, resolvedSpace)
3535
const setRef = useCallback((group: Group | null) => {
@@ -57,10 +57,12 @@ export type XRHandJointSpaceType = XRHandJoint
5757
*/
5858
export function useXRSpace(): XRSpace
5959

60-
export function useXRSpace(type: XRInputSourceSpaceType | XRHandJointSpaceType): XRSpace | undefined
61-
6260
export function useXRSpace(type: XRReferenceSpaceType): XRReferenceSpace | undefined
6361

62+
export function useXRSpace(
63+
type: XRInputSourceSpaceType | XRHandJointSpaceType | XRReferenceSpaceType,
64+
): XRSpace | undefined
65+
6466
export function useXRSpace(type?: XRSpaceType): XRSpace | XRReferenceSpace | undefined {
6567
switch (type) {
6668
case 'grip-space':

0 commit comments

Comments
 (0)