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: missing dependency in useVideoTexture #1166

Merged

Conversation

hducati
Copy link
Contributor

@hducati hducati commented Nov 29, 2022

Why

Currently we're using useVideoTexture in our application, but when I was trying to control the start property on my end, it was not working because the array of dependencies was missing the start property. I don't know if it's the right approach to control the behavior of the start property like this, if it's not, just let me know. You can find the sample below (I'll probably change this code, because it's seems redundant, but just so you can understand the scenario):

export const VideoMaterial = ({ url }) => {
  const canPlay = useAudioPlayStore((state) => state.canPlay);
  const [start, setStart] = useState(false);
  const texture = useVideoTexture(url, {
    playsInline: true,
    start,
  });

  useEffect(() => {
    if (canPlay) setStart(true);
  }, [canPlay]);

  return <meshBasicMaterial map={texture} toneMapped={false} />;
};

As for the fix, I'm adding the start property in the array of dependencies in the useEffect.

What

I added the start property in the array of dependencies in the useEffect hook. From my understand, the start property should also have a effect in the useEffect, right? If the start is false and I want to change it to true, the .play in the useEffect will not run.

Checklist

  • Documentation updated
  • Storybook entry added
  • Ready to be merged

@vercel
Copy link

vercel bot commented Nov 29, 2022

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

Name Status Preview Updated
drei ✅ Ready (Inspect) Visit Preview Nov 29, 2022 at 11:00PM (UTC)

@codesandbox-ci
Copy link

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 b0b4956:

Sandbox Source
billowing-forest-69b59f Configuration
Ground reflections and video textures Configuration
arc-x-pmndrs-colors Configuration

@github-actions
Copy link

github-actions bot commented Dec 4, 2022

🎉 This PR is included in version 9.46.2 🎉

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