Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

105
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!