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

82
Views
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 answers
Answer question

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 Report
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!