Skip to content

Commit

Permalink
refactor(rename): throttleOptions -> ThrottleOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
wangcch committed Apr 16, 2020
1 parent 6efabfc commit 05ff61f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import useThrottle from "./useThrottle";
import useThrottleFn from "./useThrottleFn";
import useThrottleFn, { ThrottleOptions } from "./useThrottleFn";

export { useThrottle, useThrottleFn };
export { useThrottle, useThrottleFn, ThrottleOptions };
4 changes: 2 additions & 2 deletions src/useThrottle.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState, useEffect, useRef } from "react";
import useThrottleFn, { throttleOptions } from "./useThrottleFn";
import useThrottleFn, { ThrottleOptions } from "./useThrottleFn";

/**
* useThrottle
Expand All @@ -11,7 +11,7 @@ import useThrottleFn, { throttleOptions } from "./useThrottleFn";
export default function useThrottle<T>(
value: T,
wait = 0,
options?: throttleOptions
options?: ThrottleOptions
): T {
const [state, setState] = useState<T>(value);

Expand Down
6 changes: 3 additions & 3 deletions src/useThrottleFn.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCallback, useRef, useEffect } from "react";

export type throttleOptions = {
export type ThrottleOptions = {
/** Specify invoking on the leading edge of the timeout. */
leading?: boolean;
};
Expand All @@ -15,11 +15,11 @@ export type throttleOptions = {
export default function useThrottleFn<T extends any[]>(
fn: (...args: T) => any,
wait = 0,
options?: throttleOptions
options?: ThrottleOptions
): { callback: (...args: T) => void; cancel: () => void } {
const timer = useRef<ReturnType<typeof setTimeout>>();
const fnRef = useRef(fn);
const optionsRef = useRef<throttleOptions | undefined>(options);
const optionsRef = useRef<ThrottleOptions | undefined>(options);
const currentArgs = useRef<any>();

fnRef.current = fn;
Expand Down

0 comments on commit 05ff61f

Please sign in to comment.