Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

106
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda