Skip to content

Commit

Permalink
fix: 🐛 Fixed husky issues
Browse files Browse the repository at this point in the history
  • Loading branch information
prc5 committed Dec 29, 2022
1 parent 6f71cda commit f005932
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -237,7 +237,7 @@ const MyComponent: React.FC = (props) => {

useThrottleEffect(() => {
// Do something
}, { executionInterval: 200, executionTimeout: false }, [props])
}, { interval: 200, timeout: false }, [props])

return (
// ...
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/use-throttle/use-throttle.hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number>(0);
const newRun = useRef<boolean>(true);
const shouldRerenderActive = useRef(false);
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/use-throttle/use-throttle.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

0 comments on commit f005932

Please sign in to comment.