Skip to content

crvN/use-throttled-effect

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

useThrottledEffect react hook

Install it with yarn:

yarn add use-throttled-effect --save

Or with npm:

npm i use-throttled-effect --save

#Example

import React, { useState } from 'react';
import useThrottledEffect  from 'use-throttled-effect';

export default function Input() {
  const [count, setCount] = useState(0);

  useEffect(()=>{
    const interval = setInterval(() => setCount(count=>count+1) ,100);
    return ()=>clearInterval(interval);
  },[])
  
  useThrottledEffect(()=>{
    console.log(count);     
  }, 1000 ,[count]);
  
  return (
    {count}
  );
}

About

A Throttle hook for react

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%