Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  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. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement