use-simple-timer
v1.0.6
Published
Simple useTimer Hook for React
Downloads
29
Readme
Simple useTimer Hook for React
🏠 Homepage
Install
npm install use-simple-timer
Usage
import useTimer from 'use-simple-timer';
const [{seconds, setSeconds, toggle, reset, isActive, setIsActive, isPaused, setIsPaused}] = useTimer()
Available variables
seconds:number -> The seconds that passed.
setSeconds:React.Dispatch<React.SetStateAction<number>> -> Sets the seconds to a value(use milliseconds, i.e. if you want to set the seconds to 3, then setSeconds(3000)).
toggle:()=>void -> toggles the isActive variable.
reset:()=>void -> resets the timer(i.e. if seconds is 3, then after calling reset, seconds will be 0. Does not stop the timer).
isActive:boolean -> returns true if timer is active, false if it is stopped. Default = true.
setIsActive:React.Dispatch<React.SetStateAction<boolean>> -> Sets isActive.
isPaused:boolean -> returns true if timer is paused, false if it is not paused. Default = false.
setIsPaused:React.Dispatch<React.SetStateAction<boolean>> -> Sets isPaused.
Modify the time for the timer
const [{seconds}] = useTimer(3000) - Now the timer works once every 3 seconds. Default is 1 second if no number is specified.
Author
👤 Baba Dan Constantin
- Website: Baba Dan Constantin
- Github: @danifullstackengineer
🤝 Contributing
Contributions, issues and feature requests are welcome!Feel free to check issues page. You can also take a look at the contributing guide.
Show your support
Give a ⭐️ if this project helped you!
📝 License
Copyright © 2022 Baba Dan Constantin. This project is MIT licensed.
This README was generated with ❤️ by readme-md-generator