@@ -10,8 +10,8 @@ const App = () => {
1010 const playerRef = useRef < HTMLVideoElement | null > ( null ) ;
1111 const urlInputRef = useRef < HTMLInputElement | null > ( null ) ;
1212
13- const [ state , setState ] = useState ( {
14- src : '' ,
13+ const initialState = {
14+ src : undefined ,
1515 pip : false ,
1616 playing : false ,
1717 controls : false ,
@@ -26,9 +26,15 @@ const App = () => {
2626 seeking : false ,
2727 loadedSeconds : 0 ,
2828 playedSeconds : 0 ,
29- } ) ;
29+ } ;
30+
31+ type PlayerState = Omit < typeof initialState , 'src' > & {
32+ src ?: string ;
33+ } ;
34+
35+ const [ state , setState ] = useState < PlayerState > ( initialState ) ;
3036
31- const load = ( src : string ) => {
37+ const load = ( src ? : string ) => {
3238 setState ( prevState => ( {
3339 ...prevState ,
3440 src,
@@ -43,7 +49,7 @@ const App = () => {
4349 } ;
4450
4551 const handleStop = ( ) => {
46- setState ( prevState => ( { ...prevState , src : '' , playing : false } ) ) ;
52+ setState ( prevState => ( { ...prevState , src : undefined , playing : false } ) ) ;
4753 } ;
4854
4955 const handleToggleControls = ( ) => {
@@ -187,7 +193,7 @@ const App = () => {
187193
188194 const handleLoadCustomUrl = ( ) => {
189195 if ( urlInputRef . current ?. value ) {
190- setState ( prevState => ( { ...prevState , src : urlInputRef . current ?. value || '' } ) ) ;
196+ setState ( prevState => ( { ...prevState , src : urlInputRef . current ?. value } ) ) ;
191197 }
192198 } ;
193199
@@ -266,7 +272,7 @@ const App = () => {
266272 < button type = "button" onClick = { handleClickFullscreen } >
267273 Fullscreen
268274 </ button >
269- { ReactPlayer . canEnablePIP ?.( src ) && (
275+ { src && ReactPlayer . canEnablePIP ?.( src ) && (
270276 < button type = "button" onClick = { handleTogglePIP } >
271277 { pip ? 'Disable PiP' : 'Enable PiP' }
272278 </ button >
0 commit comments