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

84
Visualizações
How to make js working for component inside component in React?

Hi I want to call some countdown timer in side other component in react but my JS doesn't work. When I put component outside the other ,my JS is working fine. I want it to put it inside the GlowBox component. Like I said when I put it out the GlowBox everything is fine and working perfect.

import React, { Fragment } from 'react';

const Clock = ({ timerMinutes, timerSeconds }) => {
  return (
    <Fragment>
      ...
    </Fragment>
  );
};

Clock.defaultProps = {
  timerMinutes: 3,
  timerSeconds: 0,
};

export default Clock;

!

import React, { useState, useEffect } from 'react';
function App() {
  const [timerMinutes, setTimerMinutes] = useState();
  const [timerSeconds, setTimerSeconds] = useState();

  let interval;

  const startTimer = () => {
    const countDownDate = new Date('May 30,2023 ').getTime();

    interval = setInterval(() => {
      const now = new Date().getTime();

      const distance = countDownDate - now;

      const minutes = Math.floor((distance % (60 * 60 * 1000)) / (1000 * 60));
      const seconds = Math.floor((distance % (60 * 1000)) / 1000);

      if (distance < 0) {
        // Stop Timer

        clearInterval(interval.current);
      } else {
        // Update Timer
        setTimerMinutes(minutes);
        setTimerSeconds(seconds);
      }
    });
  };

  useEffect(() => {
    startTimer();
  });
  return (
    <div>
      <div className='divBut'>
        <NavBar></NavBar>, <NavBar type={'drugi'}></NavBar>,<NavBar></NavBar>
      </div>
      <GlowBox>
        
        <div className='App'>
          <LeftSide timerMinutes={timerMinutes} timerSeconds={timerSeconds} />
        </div>
      </GlowBox>
    </div>
  );
}

export default App;

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I think this is because your LeftSide component is inside GlowBox, wich means it can access only props from GlowBox, not state. It is nested.

For the Navbar it can work if you try to access state, because they are not nested in a React component. Try to remove the LeftSide component from Glowbox or open the GlowBox component and put LeftSide inside it (inside its file)

about 4 years ago · Juan Pablo Isaza Relatório
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