Questions tagged [setinterval]

setInterval is a global JavaScript method. It is used to execute a particular function or piece of code at regular intervals.

Filter by
Sorted by
Tagged with
-4 votes
1 answer
38 views

What is the purpose of using "Null" as a condition into IF statements? [closed]

I'd like to create a timer using JavaScript but I had this problem when I wanted to understand the code: What is the purpose of writing this code in if statements : let [seconds, minutes, hours] = [0, ...
失敗者此人's user avatar
0 votes
0 answers
25 views

Need help showing animation on canvas without reloading image at every interval (React)

EDIT: This is how I managed to make it work. I realized I had to create the image object inside the initial useEffect hook to prevent it from being reloaded at every re-render, and refer to it later ...
Priit Kenkmann's user avatar
0 votes
2 answers
70 views

setInterval and clearInterval in javaScript

let count = 0; function printCount() { console.log("Count:", count); count++; if (count > 5) { clearInterval(intervalId); } } let intervalId = setInterval(printCount, 1000); ...
Haile Zerfu's user avatar
0 votes
1 answer
32 views

SetInterval function not triggering in for loop (nodejs, express, socket.io)

I have a function called when a game starts. "lobby.players" is an object with 2 socket objects inside. I've assigned setInterval to the update variable of each player (socket) object. But ...
Martin Brůžek's user avatar
0 votes
1 answer
23 views

Need some help to figure out why Mozmobilemessage(SMS) fucntion is not working with setinterval to send scheduled SMS to a mobile phone

Been trying to get to the bottom of this for a couple of days now. For some reasons the mozmobilemessage function doesn't seem to work properly with setIntervals (using the script on KaiOS 2.5 app). ...
waj's user avatar
  • 1
0 votes
0 answers
13 views

Test Set Interval with Jest

I'm trying to test an API that should be called during each interval (10 minutes). But whenever I run my test suite, I'm getting a timeout error. My idea was to: Set an initial time jest....
EmptyK97's user avatar
-3 votes
2 answers
64 views

React setState and interval [closed]

I don't understand why currentExpVal is always has a value of 0. It means the interval doesn't stop. Could anybody explain it? I want to have a smoothly updating counter during interval until it's not ...
Dmytro Khilchuk's user avatar
-1 votes
1 answer
42 views

A stopwatch with React and setInterval: how to fix the missing timer id issue?

I'm trying to create a stopwatch in a React app. Inside a component (well, currently inside App() created with vite), I have the following bits: const [elapsedTime, setElapsedTime] = useState(0) // ...
YakovL's user avatar
  • 7,734
0 votes
1 answer
46 views

React & State to create a timer

I am making a timer using React & State only, there is Session time which is set to 2 minutes and Break time, set to 1 minute. When play button is clicked, the timer will start decrementing the ...
paldong's user avatar
2 votes
3 answers
144 views

SetInterval not working properly in ReactJS and Chrome

so I have a react modal which has a countdown timer. The timer doesn't seem to work on Chrome but works on Firefox. On Chrome timer starts to count down but decreases its ticking pase when it ticks ...
labs's user avatar
  • 909
0 votes
1 answer
35 views

clear interval on hover with react

I've got a carousel with an interval in a useEffect hook to trigger automatic slide. I'd like to stop the auto slide as long as I'm hovering the whole section. useEffect(() => { const timer = ...
Horkos's user avatar
  • 231
0 votes
0 answers
26 views

How to prevent Chrome interference with setInterval

My JavaScript setInterval call is setup to run my callback every 30 seconds. But it is not firing at expected frequency when the tab stays in background for sometime. Chrome does throttling of timers ...
rachitiitr's user avatar
1 vote
1 answer
42 views

setInterval does not use updated values of useState variables

This is a useEffect function, shopId is updated once, so I assume it run once. even though I call the setOrder function the order variable is not recongnized as updated in here, it is updated in other ...
Pnina's user avatar
  • 25
0 votes
3 answers
74 views

Why stop button is not working in my javascript code?

// generate a random color - random hex value const randomColor = function () { const hex = '0123456789ABCDEF'; let color = '#'; for (let i = 0; i < 6; i++) { color += hex[Math.floor(...
kunal bandale's user avatar
0 votes
1 answer
121 views

setInterval and useState problems while building a timer clock

Description: So I am building a planning feature for my room meeting app. I have a timer clock and a timeline with stops. If the timeclock reaches 00:02, then the respective text (00:02) will turn ...
khoaoaoaoa's user avatar
0 votes
0 answers
23 views

React Native setinterval Memory Leak

I have a memory leak for a simple timer using a setInterval (I have similar functions with the same problem and I am using this to debug) with this set up in React Native. I do not know how to stop ...
mlav's user avatar
  • 1
0 votes
0 answers
22 views

Setting State with Set Interval in React Native

I have a async function that outputs an array. I have a useeffect that has this function (get array) defined inside of it. Then I call a timer inside the useeffect to continuously run the function. ...
mlav's user avatar
  • 1
0 votes
0 answers
24 views

Amcharts 5 setInterval(function()) - intermittent 404 error

I'm writing a one line data file every 3 seconds on local pc and uploading to server where it is read by amcharts setInterval(function). It works well generating a "live" chart but it also ...
smokeStack's user avatar
1 vote
1 answer
34 views

Change interval multipling it by a number inside an array using react

I want to modify the timing at which console.log(prevIndex) is displayed by adjusting the speed array using currentLocationIndex to iterate over [1, 5, 6, 2, 3, 4]. The current code does not produce ...
Lucas Santana Figueiredo's user avatar
1 vote
1 answer
23 views

How do I make text flash that's already inside a setInterval + loop

I have a script for reply times in a queue system. I would like the text that gets highlighted red/orange to flash. I am unsure how to do this as it's already inside a setInterval block that also ...
Joe's user avatar
  • 11
0 votes
1 answer
43 views

clearInterval doesn't work (React-Native Javascript)

I am currently working on a React-Native app, for some reason I am unable to clear the interval that I have set earlier. It simply wont work no matter what I try. here's my code if you guys could give ...
Rémi-Antoine Joron's user avatar
0 votes
1 answer
62 views

How do I more properly utilize useEffect and useFrame to calculate this n-body simulation?

I have been working on a brute force approach for a n-body simulation based on this exercise I stumbled upon: https://www.cs.princeton.edu/courses/archive/fall03/cs126/assignments/nbody.html The code ...
jerome's user avatar
  • 1
1 vote
1 answer
24 views

How to make Intervals go in a row?

I've been trying to make a Pomodoro timer with user's defined time to work and rest. I have a Timer component that have this starting logic: useEffect(() => { start(3); start(timeData....
IglKa11's user avatar
  • 23
0 votes
0 answers
17 views

Print separate paragraph while user is taking pause for certain time limit

I am building Voice to text app in React.js using https://www.npmjs.com/package/react-speech-recognition#developing. I want to detect whether user is giving a pause and print it as a separate ...
Rubasri Srikanthan's user avatar
0 votes
0 answers
41 views

why does window.setInterval thing stops working after about 62 seconds [duplicate]

For some reason the window.setInterval thing stops working after about 60 seconds if its window is not visible enough. Does anybody know how I can make it continue until I tell it to stop? Here is a ...
George Keeling's user avatar
1 vote
0 answers
68 views

setInterval calls the function just once

I'm trying to execute the function below every 500ms function moveActualCam(where) { console.log("Called"); seq_json = { direzione: where, }; async function postData()...
NicoCaldo's user avatar
  • 1,265
0 votes
1 answer
26 views

Fail to update value using window.setInterval, useEffect and useState

Here, I am simulating a timer with some model result that depends on the timer value. I want to update the timer while changing the model value every second. "use client"; import { useState,...
TungTung's user avatar
  • 197
0 votes
0 answers
50 views

API call in React is leading to performance issues

I have created a table of components, where each row of the component, separately calls the backend api, that I have created using express.js after every 5 seconds, as can be seen here. import {...
suraj Mandal's user avatar
0 votes
2 answers
105 views

Make a request every 100 ms with setInterval, but the request can sometimes take more than 100 ms

I need to update an image in a <canvas> 10 times per second, with data coming from an HTTP request: var i = 0; setInterval(() => { i += 1; console.log("sending request", i); ...
Basj's user avatar
  • 42.4k
1 vote
1 answer
36 views

How to make an animation to draw a triangle every second on canvas in javascript?

I am learning javascript on the site mdn Drawing graphics and its first example draws a lot of triangles on canvas when open the web here's the original code the site provided: const canvas = document....
susanliu's user avatar
0 votes
1 answer
42 views

What is wrong with this button? (javascript)

I am making a nice little button game. It'll probably get dark at the end. I just started earlier, and I'm at a problem. I'll display my code below and then explain my problem. HTML: <button ...
Maze's user avatar
  • 1
1 vote
2 answers
218 views

Issue using setInterval with Next.js

I was creating a progress bar component with Next.js and tailwind.css and using JavaScript setInterval() function to animate it. Here is the code below: import React, { useState } from "react&...
Alharith Albayati 's user avatar
0 votes
0 answers
40 views

Nodejs setInterval callback issue

I am facing a issue in extracting the current time value from setInterval function. Here is my nodejs code export const countDownTimer = async (req, res, next) => { try { var time = 120; var ...
ksdev's user avatar
  • 1
1 vote
1 answer
27 views

React Native - Accessing several states inside of an interval function

Sorry, not sure what the best way to word this question is. I've run into a problem where I have an interval which acts as the main loop for my program. I have a complex state object which I need to ...
sthiessen's user avatar
2 votes
1 answer
50 views

How to use setinterval correctly in React

Why does the count increase by two each time using setinterval in react,The React version is 18 const [count, setCount] = useState(0) useEffect(() => { setInterval(() => { setCount(...
simba's user avatar
  • 21
0 votes
0 answers
42 views

Do I need to use clearInterval() when a React component is unmounted?

What's up guys, I'm new to React so i met this code const KeywordCycler = () => { const [isIntervalActive, setIsIntervalActive] = useState(false); const [currentIndex, setCurrentIndex] = ...
ziad ali gom3a's user avatar
0 votes
1 answer
44 views

ReactJS setInterval not working as expected

I’m facing an issue with a timer that I want to establish in a react component but it’s giving me headache. This is my current code: const [dataStream, setDataStream] = useState(Array.from({ length: ...
Traxan's user avatar
  • 70
0 votes
1 answer
75 views

Clear interval is not stopping the Set interval ? , Set interval keep on calling the function in vanilla javascript

The below function is executed when the user press a button and video is in play event , below the set interval is set , it will keep on calling the function for every 100 milli seconds. video....
mat's user avatar
  • 23
1 vote
1 answer
45 views

JavaScript setTimeout() and setInterval() glitching after a min

HTML Code: <div class="container"> <div> <h1 class="scrambleanimation">Creative Agency</h1> <h1 class="scrambleanimation"&...
muzzammil professionaltech's user avatar
0 votes
1 answer
57 views

SetInterval withing a Promise

const navTimeout = new Promise((resolve, reject) => { setInterval(async () => { try { await workbook.xlsx.readFile("variables.xlsx") const sheet = ...
Vivek Y V's user avatar
0 votes
1 answer
40 views

Javascript setInterval function not setting alpha every second [duplicate]

export class Lightning{ constructor(game){ this.game = game; this.width = 640; this.height = 480; this.alpha = 0.0; } update(){ //should cause ...
Jleger91's user avatar
1 vote
1 answer
40 views

How to stop setInterval inside a function using Event Listener in JS

I created a countdown timer function for a bank application wherein this timer will start the countdown once the user started login into the application. //TIMEOUT TIMER FUNCTION const timeOutTimer = (...
mikee's user avatar
  • 11
-2 votes
2 answers
55 views

ClearInterval() although with ID is not working

I have a code when a timer is shown and removed using 2 functions repeatedly by using SetInterval. However when the timer is finished I am trying to clear the SetInterval With ClearInterval but this ...
Mehdi's user avatar
  • 71
0 votes
0 answers
25 views

setInterval and clearInterval for rock paper scissors

I am new to JS and trying to finish Rock, Paper, Scissors, Lizard, Spock game. The only thing left to fix is shuffle emoji speed if I press 'Next round' button more than once. I am struggling with ...
Ada's user avatar
  • 1
0 votes
1 answer
50 views

Best approach to game loop timer in typescript with no animation

Suppose I have a react native typescript app, and I have a class Game that has a method startTimer(). When startTimer is called, it need to start running a game loop, which means it needs to call the ...
Marc's user avatar
  • 3,466
0 votes
3 answers
54 views

setInterval() giving unexpected results while updating the state of React components

I am trying to create a counter which decreases every second after clicking on it. The initial state of the clock is 25:00 which is rendered as {timerMinutes}:{timerSeconds} in the Timer component. I ...
Satyam Rai's user avatar
0 votes
1 answer
52 views

How to close triggered popup function in SetTimeout?

I am customizing the code for a UNA CMS community site that uses PHP, JavaScript, jQuery, XML, etc. UNA has a unique problem in that you can attach link data using iFramely but the video thumbnail ...
JustAnotherCoder's user avatar
0 votes
1 answer
56 views

Updating state in React is causing abnormal results from setInterval function

I am trying to create a stopwatch functionality. I am using the setInterval function to increment my timer variable per 1000ms. Everything works very well at this point. However, when I try to include ...
Ingenious Goldie's user avatar
0 votes
1 answer
23 views

How to set timer, for example 01:24:40:15 (dd HH:mm:ss) format in Angular 11,12,13,14 etc and javascript

Want to set Time in dd HH:mm:ss format
The Losers Club's user avatar
0 votes
1 answer
38 views

I need to update the 2 different <p>tag with the strings stored in 2 different arrays using single function

I need to update the 2 different <p> tags with the stings stored in 2 different arrays using a single function. The output I am getting is 'apple' 'bmw'. I need to change the content of the <...
Aravind's user avatar
  • 11

1
2 3 4 5
95