“Tetapkan interval bereaksi” Kode Jawaban

JavaScript SetInterval

setInterval(function(){ 
	console.log("Oooo Yeaaa!");
}, 2000);//run this thang every 2 seconds
Grepper

Tetapkan interval bereaksi

useEffect(() => {
  const interval = setInterval(() => {
    console.log('This will run every second!');
  }, 1000);
  return () => clearInterval(interval);
}, []);
Lonely Lyrebird

SetInterval Bereaksi

let myCounter = 0;
let timeout = null;
export default CounterApp = props => {

  const [counter, setCounter] = useState(0);

  // Also don't forget this
  useEffect(()=> {
    return ()=> clearInterval(timeout);
  }, []);      

  myCounter = counter;
  const startInterval = () => {
    timeout = setInterval(() => {
      setCounter(counter => counter + 1);
      console.log("counter: ", myCounter); // counter always return 0 but myCounter the updated value
      if(myCounter === 10) clearInterval(timeout);

    }, 1000);
  };

}
Embarrassed Elk

Jawaban yang mirip dengan “Tetapkan interval bereaksi”

Pertanyaan yang mirip dengan “Tetapkan interval bereaksi”

Lebih banyak jawaban terkait untuk “Tetapkan interval bereaksi” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya