react-xr icon indicating copy to clipboard operation
react-xr copied to clipboard

docs: update Hit Test tutorial to use getInputSourceState instead of deprecated useXRHandState

Open micronic85 opened this issue 4 months ago • 4 comments

This PR updates the Hit Test tutorial (hit-test.md) to replace the deprecated useXRHandState hook with the current getInputSourceState approach from @react-three/xr.

Changes:

  • Replaced all references to useXRHandState with getInputSourceState
  • Adjusted related explanation text and code samples
  • Ensured consistency with current API usage

Let me know if any further tweaks are needed!

micronic85 avatar Jul 28 '25 20:07 micronic85

Thanks for the PR!

The correct hook in this case is "useXRInputSourceStateContext()", so the developer does not have to provide information about the input source type and its handedness because its provided through the context :)

bbohlender avatar Jul 28 '25 23:07 bbohlender

Thanks for the clarification, @bbohlender!

That makes sense. Using useXRInputSourceStateContext() is indeed a better approach as it automatically retrieves the type and handedness from the context, simplifying the API for the user.

I've updated the PR to replace xr.getInputSourceState("hand", "right") with useXRInputSourceStateContext() as suggested.

const store = createXRStore({
  hand: {
    right: () => {
      const state = useXRInputSourceStateContext();
      // ...
    }
  }
});

This makes it clearer how the state retrieved from the context is then used within the hand configuration function.

micronic85 avatar Jul 29 '25 15:07 micronic85

@micronic85 I don't see the update you mentioned beeing applied to the files :)

bbohlender avatar Jul 29 '25 15:07 bbohlender

@bbohlender, I've updated the code

micronic85 avatar Jul 29 '25 15:07 micronic85