SHARE
TWEET

Untitled

a guest Jul 18th, 2019 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import {useState} from 'react';
  2.  
  3.  
  4. export const useCounter = (start, finish, step) => {
  5.     //Definition of our state
  6.    
  7.     const [count, setCount] = useState(start);
  8.    
  9.     //Implementation of our handleCount method
  10.    
  11.     const handleCount = () => {
  12.         if (count === finish) {
  13.             return setCount(start);
  14.         } else {
  15.             return setCount(count + step);
  16.         }
  17.     };
  18.    
  19.     //Return our custom hook array
  20.    
  21.     return [count, handleCount]
  22. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top