-
Notifications
You must be signed in to change notification settings - Fork 55
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
Using ref-property #339
Comments
Issue Label Bot is not confident enough to auto-label this issue. See dashboard for more details. |
Message that will be displayed on users' first issue |
@mnervik Can you share code or snippet of example? |
@all-contributors please add @mnervik for Bug reports |
I've put up a pull request to add @mnervik! 🎉 |
@all-contributors please add @mnervik for Bug reports |
I've put up a pull request to add @mnervik! 🎉 |
For testing I created a react app using the What I was using in plyr-react@2.2.0
This works and tells me what the ref-element is in the console What I am using in plyr-react@3.0.3
This does not work, and tells me that the variable is ALWAYS undefined and and that |
@mnervik I think I've got a fix for it. Try it out by changing your {
// ...
"plyr-react": "git+https://github.com/chintan9/plyr-react.git#fix/forward-ref",
} then run Let me know if it works. |
Yeah, it works |
@mnervik It is fixed v3.0.4 |
Eh, apparently I't not quite that easy 😄
and if you try to return the App.js
|
@mnervik I didn't use export default function App() {
const ref = useRef<HTMLPlyrVideoElement>()
const [currentTime, setCurrentTime] = useState('0.00')
const [id, setId] = useState<NodeJS.Timeout>()
useEffect(() => {
const onPlay: PlyrCallback = (event) => {
setId(
setInterval(() => {
const currentTime = ref?.current?.plyr?.currentTime / 100
setCurrentTime(currentTime.toFixed(2))
}, 1000)
)
}
const onPause: PlyrCallback = (event) => {
clearInterval(id)
}
const onEnded: PlyrCallback = (event) => {
clearInterval(id)
setCurrentTime('0.00')
}
ref?.current?.plyr?.on('play', onPlay)
ref?.current?.plyr?.on('pause', onPause)
ref?.current?.plyr?.on('ended', onEnded)
return () => {
ref?.current?.plyr?.off('play', onPlay)
ref?.current?.plyr?.off('pause', onPause)
ref?.current?.plyr?.off('ended', onEnded)
}
}, [])
return <>
<Plyr ref={ref} />
<>
} Note: I just added the types so they are not available yet. |
That second point is the main reason why this probably would not be the ideal situation. It just seems like a bunch of work to get a kind of ghetto solution of something that already worked in the previous version. Also, correct me if I'm wrong, but I think useRef is only for functional components, and there are not really any viable alternatives for classes. To clarify that last point, this is all I needed before when creating an event for plyr
Simple and easy to understand, and I don't have to code any logic to handle the properties from plyr, they are ready for use when you need them. |
@mnervik If you're still using |
That seems to work just fine |
@mnervik Please use v3.0.5 Thanks @iwatakeshi for fix |
@iwatakeshi getting error CODE const PlayerView = () => {
const ref = useRef();
useEffect(() => {
ref.current.plyr.on("ended", (event) => {
console.log("ended-event");
})
}, [])
return (
<Plyr
id="player"
options={{ ...options, controls }}
source={src}
ref={ref}
/>
);
} |
Hi @ajithofficial, Setting an event listener needs the latest plyr instance to be available, I believe that this issue comment will make things more clear (#732 (comment)) |
In my project I'm using
ref
to get the video-element, but that is no longer working as of 3.0.0Any chance of making it work again, or to make an alternative way to get the VideoElement-node?
The text was updated successfully, but these errors were encountered: