79129731

Date: 2024-10-27 01:03:32
Score: 2.5
Natty:
Report link

There should not be an issue with re-rendering every second. Infact in a clock like this that should be desirable. Have you checked if your clock is working?

  useEffect(() => {
        let now = new Date()
        while (now.getSeconds() !== 0) {
            const interval = window.setInterval(() => {now = new Date()}, 1000)
            return () => window.clearInterval(interval);
        }
        setTime(now);
    }, [])

You seem to return out of your useEffect before you've set state. Which means your UI would not be receiving any state updates.

useEffect(() => {
    // Adjust this to 60 * 1000 for 1 min (not required)
    const refreshTime = 1000;
    const interval = setInterval(() => {
      setTime(new Date())
    }, refreshTime)

    return () => {
      clearInterval(interval)
    }
  }, []);
Reasons:
  • RegEx Blacklisted phrase (2): working?
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: Anubhav