Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

107
Vistas
How can I set a default video in my player with componentDidMount?

I am making a video player in React that fetches API from yt and you can search videos and it shows them. Everything works fine but when the app first loads the search is empty, so I want it to have a video there as default when it loads, using componentDidMount. but I cannot figure out how to write my componentDidMount so it fetches the url and plays the video when it first renders.

here is my whole App component.

class App extends React.Component {
state = {
    videos: [],
    selectedVideo: null
}

componentDidMount() {
    //fetch("https://www.youtube.com/watch?v=EaswWiwMVs8")
       // .then((response) => response.json())
       

}


handleSubmit = async (termFromSearchBar) => {
    const response = await youtube.get('/search', {
        params: {
            q: termFromSearchBar
        }
    })

    this.setState({
        videos: response.data.items
    })
    console.log("this is resp", response);
};
handleVideoSelect = (video) => {
    this.setState({ selectedVideo: video })
}

render() {
    return (
        <div className='ui container' style={{ marginTop: '1em' }}>
            <SearchBar handleFormSubmit={this.handleSubmit} />
            <div className='ui grid'>
                <div className="ui row">
                    <div className="eleven wide column">
                        <VideoDetail video={this.state.selectedVideo} />
                    </div>
                    <div className="five wide column">
                        <VideoList handleVideoSelect={this.handleVideoSelect} videos={this.state.videos} />
                    </div>
                </div>
            </div>
        </div>
    )
 }
 }

 export default App;
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda