Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't call a hook in onChange for KeyboardControls #1279

Merged
merged 1 commit into from
Feb 10, 2023

Conversation

will-wow
Copy link
Contributor

@will-wow will-wow commented Feb 9, 2023

Why

Passing an onChange callback to KeyboardControls triggers a Rules of Hooks error when a key is pressed.

See screenshot:

onChange-bad

What

In src/web/KeyboardControls.tsx, the onChange callback tries to get the state of the pressed keys by calling api[2], which is a reference to useControls. It looks like that should be api[1], which is a reference to useControls.getState and can safely be called at keypress time.

So this PR fixes that, and adds an example of an onChange handler to the Storybook story to test that by changing the color of the Player when the user clicks Space.

See screenshot

onChange-good

Checklist

  • Storybook entry added
  • Ready to be merged

Also just wanted to say thanks for this library! This and R3F have made making 3D AR applications so much more pleasant 😄

@vercel
Copy link

vercel bot commented Feb 9, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
drei ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Feb 9, 2023 at 7:39PM (UTC)

@codesandbox-ci
Copy link

codesandbox-ci bot commented Feb 9, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 3d12ed0:

Sandbox Source
still-frost-5ezzok Configuration
Ground reflections and video textures Configuration
arc-x-pmndrs-colors Configuration

@github-actions
Copy link

🎉 This PR is included in version 9.56.21 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants