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

💭 What is the best way to set a React state from a Frame processor? #2731

Closed
3 of 4 tasks
frodriguez-hu opened this issue Apr 9, 2024 · 1 comment
Closed
3 of 4 tasks
Labels
💭 question Further information is requested

Comments

@frodriguez-hu
Copy link

Question

Hey! I am wondering what is the best way to do what I am asking on the title. Which is the right worklet function or hook I should use?

What I tried

I am executing this on the frame processor:

Worklets.createRunInJsFn(

And inside that function I am using a sharedValue from the the worklet library.

I mean, I have things like this around all the code:

if (!isInsideLogic.value) {
          eventRegister.value = 0;
          isInsideLogic.value = true;
          setIsInside(true);
        }

A logic value coming from the useSharedValue so I do not use the state value which will have a wrong value cause the frames are executing super fast compared to the React life cycle.
By doing that, it is working but I am not sure if it is the best way.

VisionCamera Version

3

Additional information

@frodriguez-hu frodriguez-hu added the 💭 question Further information is requested label Apr 9, 2024
@mrousavy
Copy link
Owner

React state is much slower than shared values. Only need it if you don't expect it to change often, like hasFacesInView or something like that. That's fine.

For some realtime stuff, use Skia or SharedValues instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💭 question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants