react-jsbox
Advanced tools
Comparing version 1.0.5 to 1.0.6
{ | ||
"name": "react-jsbox", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "A custom React renderer for writing JSBox apps in React.", | ||
@@ -27,13 +27,13 @@ "keywords": [ | ||
"devDependencies": { | ||
"@babel/core": "^7.10.1", | ||
"@babel/core": "^7.10.2", | ||
"@babel/plugin-proposal-class-properties": "^7.10.1", | ||
"@babel/plugin-proposal-decorators": "^7.10.1", | ||
"@babel/plugin-transform-runtime": "^7.10.1", | ||
"@babel/preset-env": "^7.10.1", | ||
"@babel/preset-env": "^7.10.2", | ||
"@babel/preset-react": "^7.10.1", | ||
"@babel/runtime": "^7.10.1", | ||
"@babel/runtime": "^7.10.2", | ||
"babel-eslint": "^10.1.0", | ||
"babel-plugin-annotate-pure-calls": "^0.4.0", | ||
"babel-preset-minify": "^0.5.1", | ||
"eslint": "^7.1.0", | ||
"eslint": "^7.2.0", | ||
"eslint-plugin-babel": "^5.3.0", | ||
@@ -45,3 +45,3 @@ "eslint-plugin-import": "^2.20.2", | ||
"react": "^16.13.1", | ||
"rollup": "^2.11.2", | ||
"rollup": "^2.14.0", | ||
"rollup-plugin-babel": "^4.4.0", | ||
@@ -48,0 +48,0 @@ "rollup-plugin-cleanup": "^3.1.1", |
import useCache from './useCache' | ||
import useDebounce from './useDebounce' | ||
import useEventHandler from './useEventHandler' | ||
import useFirstMountState from './useFirstMountState' | ||
import useLatest from './useLatest' | ||
import useRendersCount from './useRendersCount' | ||
import useTimeoutFn from './useTimeoutFn' | ||
import useUpdate from './useUpdate' | ||
import useUpdateEffect from './useUpdateEffect' | ||
@@ -8,3 +14,9 @@ export default { | ||
useDebounce, | ||
useEventHandler | ||
useEventHandler, | ||
useFirstMountState, | ||
useLatest, | ||
useRendersCount, | ||
useTimeoutFn, | ||
useUpdate, | ||
useUpdateEffect | ||
} |
import {useEffect} from 'react' | ||
import useTimeoutFn from './useTimeoutFn' | ||
const useDebounce = (fn, ms = 0, args = []) => { | ||
useEffect(() => { | ||
const handle = setTimeout(fn.bind(null, args), ms) | ||
export default function useDebounce(fn, ms = 0, deps = []) { | ||
const [isReady, cancel, reset] = useTimeoutFn(fn, ms) | ||
return () => { | ||
// if args change then clear timeout | ||
clearTimeout(handle) | ||
} | ||
}, [args]) | ||
useEffect(reset, deps) | ||
return [isReady, cancel] | ||
} | ||
export default useDebounce |
@@ -6,3 +6,3 @@ import view from './components/view' | ||
export default { | ||
const hostConfig = { | ||
now, | ||
@@ -132,1 +132,3 @@ | ||
} | ||
export default hostConfig |
Sorry, the diff of this file is too big to display
108342
23
695