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

Question: How do I use setters with a ref? #998

Open
Johannes5 opened this issue Nov 25, 2022 · 2 comments
Open

Question: How do I use setters with a ref? #998

Johannes5 opened this issue Nov 25, 2022 · 2 comments
Labels
discussion question Further information is requested

Comments

@Johannes5
Copy link

Johannes5 commented Nov 25, 2022

Plyr has setters and getters:
image

I would like to use shortcuts to change the playing speed.
According to the above examples, with plyr this would be done with
player.speed = 1.8

But since I am using the forwarded ref from a custom plyr instance I've tried it like this:
image

I've gotten the error message that the left-hand side of the argument is invalid and realized that setting on a ref is pointless

So do I use plyrs setters in my situation?

@realamirhe
Copy link
Collaborator

realamirhe commented Nov 26, 2022

Hey @Johannes5

The speed & volume are attributes that options props received, so you can store them in the state (or ref) conditionally and re-render your component with new speed. Is that solve your problem?

@Johannes5
Copy link
Author

image

With the above code I wasn't able to set the speed.

So far I was only able to set the speed inside the useEffect() inside CustomPlyrInstance via
api.plyr.speed = 1.75

Because I want to change the speed via Hotkeys - and I'm using a useHotkeys hook - I need to access this plyr instance outside the useEffect Hook.

Which begs the question - why the useEffect hook in the first place?
And - what can I do?

@realamirhe realamirhe added question Further information is requested discussion labels Feb 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants