You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Trying to create a func component player with TS and a useRef and getting compile errors
since a ref is needed for calling events on the player.
Expected Behavior
no TS compiler errors
Steps to Reproduce
// using https://github.com/cookpete/react-player// Only loads the YouTube playerimport{useRef}from'react'importReactPlayerfrom'react-player/youtube'exporttypeVidPlayerProps={sourceId?: string}exportfunctionVidPlayer(props: VidPlayerProps){constref=useRef()if(!props.sourceId)returnconsturl=`https://www.youtube.com/watch?v=`+props.sourceIdconsole.log('vidplayer',{ url })return(<ReactPlayerref={ref}className='react-player'url={url}width='100%'controls={false}onStart={()=>console.log('onStart')}/>)}
this gives one of those long typescript errors
No overload matches this call.
Overload 1 of 2, '(props: YouTubePlayerProps | Readonly<YouTubePlayerProps>): YouTubePlayer', gave the following error.
Type 'MutableRefObject<undefined>' is not assignable to type 'LegacyRef<YouTubePlayer> | undefined'.
Type 'MutableRefObject<undefined>' is not assignable to type 'RefObject<YouTubePlayer>'.
Types of property 'current' are incompatible.
Type 'undefined' is not assignable to type 'YouTubePlayer | null'.
Overload 2 of 2, '(props: YouTubePlayerProps, context: any): YouTubePlayer', gave the following error.
Type 'MutableRefObject<undefined>' is not assignable to type 'LegacyRef<YouTubePlayer> | undefined'.
This discussion was converted from issue #1768 on April 19, 2024 19:54.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Current Behavior
Trying to create a func component player with TS and a
useRef
and getting compile errorssince a ref is needed for calling events on the player.
Expected Behavior
no TS compiler errors
Steps to Reproduce
this gives one of those long typescript errors
Environment
Other Information
related #1762
Beta Was this translation helpful? Give feedback.
All reactions