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

111
Visualizações
Changing active video in React

I have a video player and a sidebar of other videos to play. I want to be able to to click a video from the sidebar and display it on the video player, replacing the default video, and remove it from the sidebar, putting the replaced video in its place. (The videos are currently just posters as there's no actual video source yet).

Currently, I've set the default video to index 0 from my JSON, and I've set a state that is connected to the sidebar which displays all the videos.

I believe I can use an event listener that takes the id (or index as that's what's being used to display the default video) of the clicked video and uses it to update the active video via the state. However, I'm not sure how to implement this and then hide the active video from the sidebar.

App.js:

class App extends Component {
  state = {
    videos: videos,
    activeVideo: videos[0],
  };

  render(props) {
    return (
      <>
        <Header />
        <VideoPlayer activeVideo={this.state.activeVideo} />
        <LowerSection videos={this.state.videos} />
      </>
    );
  }
}

Video Sidebar:

const NextVideo = (props) => {
  const videos = props.videos;
  return (
    <section className="nextVideosSection">
      <div className="nextVideosSection__content">
        {videos.map((data) => {
          return (
            <>
              <div className="nextVideosSection__image">
                <img
                  className="nextVideosSection__thumbnail"
                  src={data.image}
                  alt="thumbnail"
                />{" "}
              </div>
              <div className="nextVideosSection__text">
                <p className="nextVideosSection__videoTitle">{data.title}</p>
                <p className="nextVideosSection__videoChannel">
                  {data.channel}
                </p>
              </div>
            </>
          );
        })}
      </div>
    </section>
  );
};

JSON format:

{
    "id": "someID",
    "title": "someTitle",
    "channel": "someChannel",
    "image": "someImage.jpg"      //This is used for the video player poster
  },,,
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