cloudinary-community / cloudinary-community/next-cloudinary
[Bug] playerRef attribute is not a valid Ref
- Dominant language
- JavaScript
- Stars
- 300
- Forks
- 137
- Avg merge
- 3m
- Merged PRs (30d)
- 2
Description
# **Bug Report**
## **Describe the bug**
When passing a `playerRef` attribute, it doesn't behave as a regular ref. Example:
[I believe the problem is lying on playerRef being asynchronously set when the Cloudinary library has finally loaded.
](https://github.com/cloudinary-community/next-cloudinary/blob/main/next-cloudinary/src/components/CldVideoPlayer/CldVideoPlayer.tsx#L96)
## **Is this a regression?**
Im not sure.
## **Steps To Reproduce the error**
```
const videoRef = useRef()
const playerRef = useRef()
useEffect(() => {
// videoRef is defined and attached to the video element
// playerRef is not defined
}, [])
```
## **Expected behaviour**
To be able to watch for when the playerRef has been initialized. For example, the following should be working:
```
const videoRef = useRef()
const playerRef = useCallback(player => {
// do something with the player
}, [])
```
I'm not sure about the proper solution here but I believe the [`useimperativehandle`](https://react.dev/reference/react/useImperativeHandle#useimperativehandle) could help here.
## **CodeSandbox or Live Example of Bug**
## **Screenshot or Video Recording**
### **Your environment**
- OS: MacOS Sonoma
- Node version: 18
- Npm version:
- Browser name and version: Chrome
## **Additional context**
Just to give some context on what I'm trying to do, I would like access to the Cloudinary video player in order to attach to more events (e.g. `percentsplayed`) to track to an Analytics service.
Contributor guide
Assessment
This issue has not been assessed yet.