import { useMemo } from 'react' ; import { VideoCaptionsTrack , VideoCaptionsProp , } from '../HoverVideoPlayer.types' ; param { VideoCaptionsProp } videoCaptions returns { VideoCaptionsTrack [ ] } export default function useFormatVideoCaptions ( videoCaptions ) { return useMemo ( ( ) => { const formattedVideoCaptions = [ ] ; if ( videoCaptions != null ) { const rawVideoCaptions = Array . isArray ( videoCaptions ) ? videoCaptions : [ videoCaptions ] ; for ( let i = 0 , numCaptions = rawVideoCaptions . length ; i < numCaptions ; i += 1 ) { const captions = rawVideoCaptions [ i ] ; if ( captions && captions . src ) { formattedVideoCaptions . push ( { src : captions . src , srcLang : captions . srcLang , label : captions . label , kind : captions . kind || 'captions' , default : Boolean ( captions . default ) , } ) ; } else { console . error ( "Error: invalid value provided to HoverVideoPlayer prop 'videoCaptions'" , captions ) ; } } } return formattedVideoCaptions ; } , [ videoCaptions ] ) ; }