timer-hook
Advanced tools
Comparing version 1.0.4 to 1.0.6
@@ -24,2 +24,8 @@ "use strict"; | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
var TIMER_TYPE = { | ||
@@ -29,16 +35,19 @@ INCREMENT: 'INCREMENT', | ||
}; | ||
var defaultConfigs = { | ||
interval: 1000, | ||
initialTime: 0, | ||
step: 1, | ||
endTime: null, | ||
type: TIMER_TYPE.INCREMENT, | ||
onEnd: function onEnd() {} | ||
}; | ||
var useTimer = function useTimer(_ref) { | ||
var _ref$interval = _ref.interval, | ||
interval = _ref$interval === void 0 ? 1000 : _ref$interval, | ||
_ref$initialTime = _ref.initialTime, | ||
initialTime = _ref$initialTime === void 0 ? 0 : _ref$initialTime, | ||
_ref$step = _ref.step, | ||
step = _ref$step === void 0 ? 1 : _ref$step, | ||
_ref$endTime = _ref.endTime, | ||
endTime = _ref$endTime === void 0 ? null : _ref$endTime, | ||
_ref$type = _ref.type, | ||
type = _ref$type === void 0 ? TIMER_TYPE.INCREMENT : _ref$type, | ||
_ref$onEnd = _ref.onEnd, | ||
onEnd = _ref$onEnd === void 0 ? function () {} : _ref$onEnd; | ||
var useTimer = function useTimer(config) { | ||
var _defaultConfigs$confi = _objectSpread({}, defaultConfigs, {}, config), | ||
interval = _defaultConfigs$confi.interval, | ||
initialTime = _defaultConfigs$confi.initialTime, | ||
step = _defaultConfigs$confi.step, | ||
endTime = _defaultConfigs$confi.endTime, | ||
type = _defaultConfigs$confi.type; | ||
var isInitialLoad = (0, _react.useRef)(true); | ||
@@ -45,0 +54,0 @@ |
{ | ||
"name": "timer-hook", | ||
"version": "1.0.4", | ||
"version": "1.0.6", | ||
"description": "An easy to use timer hook for React", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -9,10 +9,16 @@ import { useState, useEffect, useRef, useCallback } from 'react'; | ||
export const useTimer = ({ | ||
interval = 1000, | ||
initialTime = 0, | ||
step = 1, | ||
endTime = null, | ||
type = TIMER_TYPE.INCREMENT, | ||
onEnd = () => { } | ||
}) => { | ||
const defaultConfigs = { | ||
interval: 1000, | ||
initialTime: 0, | ||
step: 1, | ||
endTime: null, | ||
type: TIMER_TYPE.INCREMENT, | ||
onEnd: () => { } | ||
} | ||
export const useTimer = (config) => { | ||
const { interval, initialTime, step, endTime, type } = { | ||
...defaultConfigs, | ||
...config | ||
} | ||
const isInitialLoad = useRef(true); | ||
@@ -19,0 +25,0 @@ const [time, setTime] = useState(initialTime); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11089
253