Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to use settimeout in react

JSX
import React from 'react';
export default function useTimeout(callback, delay) {
  const timeoutRef = React.useRef(null);
  const savedCallback = React.useRef(callback);
  React.useEffect(() => {
    savedCallback.current = callback;
  }, [callback]);
  React.useEffect(() => {
    const tick = () => savedCallback.current();
    if (typeof delay === 'number') {
      timeoutRef.current = window.setTimeout(tick, delay);
      return () => window.clearTimeout(timeoutRef.current);
    }
  }, [delay]);
  return timeoutRef;
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript map replace key value 
Javascript :: js to find min value in an array 
Javascript :: npm i images=pdf 
Javascript :: $(...).DataTable is not a function 
Javascript :: data attribute hide & show function syntax in jquery 
Javascript :: mongoose find 
Javascript :: Difference between “ == “ and “ === “ operators. 
Javascript :: Example React Hook 
Javascript :: jquery change label content 
Javascript :: lodash isNil 
Javascript :: js select all 
Javascript :: js get type 
Javascript :: validator.js 
Javascript :: javascript arguments 
Javascript :: js if and operator 
Javascript :: Find items from object 
Javascript :: usereduce 
Javascript :: how to open cypress 
Javascript :: like operator mangodb 
Javascript :: toast not showing 
Javascript :: why node_modules are not installed anymore 
Javascript :: array iterator javascript 
Javascript :: search for diff in two JSON 
Javascript :: Updating a nested object in a document using mongoose 
Javascript :: java script 
Javascript :: delete item from array of objects javascript 
Javascript :: side effect, useEffect 
Javascript :: react onclick remove component 
Javascript :: How to make a toggle button in Angularjs 
Javascript :: javascript set query parameters in url 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =