diff --git a/README.md b/README.md index 926eb11..8955866 100644 --- a/README.md +++ b/README.md @@ -208,8 +208,8 @@ import { useThrottleState } from "@better-hooks/performance"; const MyComponent: React.FC = () => { const [value, setValue] = useThrottleState("20px", { - executionInterval: 200, // We will save values at least once per 200ms - executionTimeout: 400 // Last set state action will get triggered after 400ms, we can also disable it + interval: 200, // We will save values at least once per 200ms + timeout: 400 // Last set state action will get triggered after 400ms, we can also disable it }) useWindowEvent("scroll", (e) => { @@ -237,7 +237,7 @@ const MyComponent: React.FC = (props) => { useThrottleEffect(() => { // Do something - }, { executionInterval: 200, executionTimeout: false }, [props]) + }, { interval: 200, timeout: false }, [props]) return ( // ... diff --git a/package.json b/package.json index f9fefed..94382fc 100644 --- a/package.json +++ b/package.json @@ -24,8 +24,7 @@ }, "scripts": { "build": "rollup -c", - "postinstall": "yarn husky install", - "prepare": "install-peers", + "prepare": "install-peers && yarn husky install", "lint": "eslint . --ext .js,.jsx,.tsx,.ts --fix", "test": "jest", "release": "yarn semantic-release" diff --git a/src/hooks/use-throttle/use-throttle.hook.ts b/src/hooks/use-throttle/use-throttle.hook.ts index ee9e371..09796e5 100644 --- a/src/hooks/use-throttle/use-throttle.hook.ts +++ b/src/hooks/use-throttle/use-throttle.hook.ts @@ -9,7 +9,7 @@ import { import { useForceUpdate } from "hooks/use-force-update"; export const useThrottle = (props?: UseThrottleProps): UseThrottleReturnType => { - const { executionInterval = 200, executionTimeout = 200 } = props || {}; + const { interval = 200, timeout = 200 } = props || {}; const lastExecution = useRef(0); const newRun = useRef(true); const shouldRerenderActive = useRef(false); @@ -33,8 +33,8 @@ export const useThrottle = (props?: UseThrottleProps): UseThrottleReturnType => rerenderActive(); }; - const intervalTime = dynamicProps?.executionInterval ?? executionInterval; - const timeoutTime = dynamicProps?.executionTimeout ?? executionTimeout; + const intervalTime = dynamicProps?.interval ?? interval; + const timeoutTime = dynamicProps?.timeout ?? timeout; const shouldCallImmediately = Date.now() >= lastExecution.current + intervalTime; if (newRun.current) rerenderActive(); diff --git a/src/hooks/use-throttle/use-throttle.types.ts b/src/hooks/use-throttle/use-throttle.types.ts index 90b807f..a2ce43e 100644 --- a/src/hooks/use-throttle/use-throttle.types.ts +++ b/src/hooks/use-throttle/use-throttle.types.ts @@ -15,9 +15,9 @@ export type UseThrottleProps = { /** * Execution interval time for triggering callback */ - executionInterval?: number; + interval?: number; /** * Callback timeout when throttling stops triggering */ - executionTimeout?: number | false; + timeout?: number | false; };