@usefy/use-throttle 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -16,6 +16,7 @@ interface UseThrottleOptions {
16
16
  /**
17
17
  * Throttles a value by limiting updates to at most once per specified interval.
18
18
  * This is implemented using useDebounce with maxWait set to the interval.
19
+ * Useful for scroll events and resize handlers.
19
20
  *
20
21
  * @template T - The type of the value to throttle
21
22
  * @param value - The value to throttle
package/dist/index.d.ts CHANGED
@@ -16,6 +16,7 @@ interface UseThrottleOptions {
16
16
  /**
17
17
  * Throttles a value by limiting updates to at most once per specified interval.
18
18
  * This is implemented using useDebounce with maxWait set to the interval.
19
+ * Useful for scroll events and resize handlers.
19
20
  *
20
21
  * @template T - The type of the value to throttle
21
22
  * @param value - The value to throttle
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/useThrottle.ts"],"sourcesContent":["export { useThrottle, type UseThrottleOptions } from \"./useThrottle\";\r\n","import { useDebounce, type UseDebounceOptions } from \"@usefy/use-debounce\";\r\n\r\n/**\r\n * Options for useThrottle hook\r\n */\r\nexport interface UseThrottleOptions {\r\n /**\r\n * Whether to update the throttled value on the leading edge\r\n * @default true\r\n */\r\n leading?: boolean;\r\n /**\r\n * Whether to update the throttled value on the trailing edge\r\n * @default true\r\n */\r\n trailing?: boolean;\r\n}\r\n\r\n/**\r\n * Throttles a value by limiting updates to at most once per specified interval.\r\n * This is implemented using useDebounce with maxWait set to the interval.\r\n *\r\n * @template T - The type of the value to throttle\r\n * @param value - The value to throttle\r\n * @param delay - The interval in milliseconds (default: 500ms)\r\n * @param options - Additional options for controlling throttle behavior\r\n * @returns The throttled value\r\n *\r\n * @example\r\n * ```tsx\r\n * function ScrollComponent() {\r\n * const [scrollY, setScrollY] = useState(0);\r\n * const throttledScrollY = useThrottle(scrollY, 100);\r\n *\r\n * useEffect(() => {\r\n * const handleScroll = () => setScrollY(window.scrollY);\r\n * window.addEventListener(\"scroll\", handleScroll);\r\n * return () => window.removeEventListener(\"scroll\", handleScroll);\r\n * }, []);\r\n *\r\n * return <div>Scroll Y: {throttledScrollY}</div>;\r\n * }\r\n * ```\r\n *\r\n * @example\r\n * ```tsx\r\n * // With leading edge only\r\n * const throttledValue = useThrottle(value, 300, { leading: true, trailing: false });\r\n * ```\r\n *\r\n * @example\r\n * ```tsx\r\n * // With trailing edge only\r\n * const throttledValue = useThrottle(value, 300, { leading: false, trailing: true });\r\n * ```\r\n */\r\nexport function useThrottle<T>(\r\n value: T,\r\n delay: number = 500,\r\n options: UseThrottleOptions = {}\r\n): T {\r\n const { leading = true, trailing = true } = options;\r\n\r\n // Throttle is implemented using debounce with maxWait set to delay\r\n return useDebounce(value, delay, {\r\n leading,\r\n maxWait: delay,\r\n trailing,\r\n });\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,0BAAqD;AAwD9C,SAAS,YACd,OACA,QAAgB,KAChB,UAA8B,CAAC,GAC5B;AACH,QAAM,EAAE,UAAU,MAAM,WAAW,KAAK,IAAI;AAG5C,aAAO,iCAAY,OAAO,OAAO;AAAA,IAC/B;AAAA,IACA,SAAS;AAAA,IACT;AAAA,EACF,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/useThrottle.ts"],"sourcesContent":["export { useThrottle, type UseThrottleOptions } from \"./useThrottle\";\r\n","import { useDebounce, type UseDebounceOptions } from \"@usefy/use-debounce\";\r\n\r\n/**\r\n * Options for useThrottle hook\r\n */\r\nexport interface UseThrottleOptions {\r\n /**\r\n * Whether to update the throttled value on the leading edge\r\n * @default true\r\n */\r\n leading?: boolean;\r\n /**\r\n * Whether to update the throttled value on the trailing edge\r\n * @default true\r\n */\r\n trailing?: boolean;\r\n}\r\n\r\n/**\r\n * Throttles a value by limiting updates to at most once per specified interval.\r\n * This is implemented using useDebounce with maxWait set to the interval.\r\n * Useful for scroll events and resize handlers.\r\n *\r\n * @template T - The type of the value to throttle\r\n * @param value - The value to throttle\r\n * @param delay - The interval in milliseconds (default: 500ms)\r\n * @param options - Additional options for controlling throttle behavior\r\n * @returns The throttled value\r\n *\r\n * @example\r\n * ```tsx\r\n * function ScrollComponent() {\r\n * const [scrollY, setScrollY] = useState(0);\r\n * const throttledScrollY = useThrottle(scrollY, 100);\r\n *\r\n * useEffect(() => {\r\n * const handleScroll = () => setScrollY(window.scrollY);\r\n * window.addEventListener(\"scroll\", handleScroll);\r\n * return () => window.removeEventListener(\"scroll\", handleScroll);\r\n * }, []);\r\n *\r\n * return <div>Scroll Y: {throttledScrollY}</div>;\r\n * }\r\n * ```\r\n *\r\n * @example\r\n * ```tsx\r\n * // With leading edge only\r\n * const throttledValue = useThrottle(value, 300, { leading: true, trailing: false });\r\n * ```\r\n *\r\n * @example\r\n * ```tsx\r\n * // With trailing edge only\r\n * const throttledValue = useThrottle(value, 300, { leading: false, trailing: true });\r\n * ```\r\n */\r\nexport function useThrottle<T>(\r\n value: T,\r\n delay: number = 500,\r\n options: UseThrottleOptions = {}\r\n): T {\r\n const { leading = true, trailing = true } = options;\r\n\r\n // Throttle is implemented using debounce with maxWait set to delay\r\n return useDebounce(value, delay, {\r\n leading,\r\n maxWait: delay,\r\n trailing,\r\n });\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,0BAAqD;AAyD9C,SAAS,YACd,OACA,QAAgB,KAChB,UAA8B,CAAC,GAC5B;AACH,QAAM,EAAE,UAAU,MAAM,WAAW,KAAK,IAAI;AAG5C,aAAO,iCAAY,OAAO,OAAO;AAAA,IAC/B;AAAA,IACA,SAAS;AAAA,IACT;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/useThrottle.ts"],"sourcesContent":["import { useDebounce, type UseDebounceOptions } from \"@usefy/use-debounce\";\r\n\r\n/**\r\n * Options for useThrottle hook\r\n */\r\nexport interface UseThrottleOptions {\r\n /**\r\n * Whether to update the throttled value on the leading edge\r\n * @default true\r\n */\r\n leading?: boolean;\r\n /**\r\n * Whether to update the throttled value on the trailing edge\r\n * @default true\r\n */\r\n trailing?: boolean;\r\n}\r\n\r\n/**\r\n * Throttles a value by limiting updates to at most once per specified interval.\r\n * This is implemented using useDebounce with maxWait set to the interval.\r\n *\r\n * @template T - The type of the value to throttle\r\n * @param value - The value to throttle\r\n * @param delay - The interval in milliseconds (default: 500ms)\r\n * @param options - Additional options for controlling throttle behavior\r\n * @returns The throttled value\r\n *\r\n * @example\r\n * ```tsx\r\n * function ScrollComponent() {\r\n * const [scrollY, setScrollY] = useState(0);\r\n * const throttledScrollY = useThrottle(scrollY, 100);\r\n *\r\n * useEffect(() => {\r\n * const handleScroll = () => setScrollY(window.scrollY);\r\n * window.addEventListener(\"scroll\", handleScroll);\r\n * return () => window.removeEventListener(\"scroll\", handleScroll);\r\n * }, []);\r\n *\r\n * return <div>Scroll Y: {throttledScrollY}</div>;\r\n * }\r\n * ```\r\n *\r\n * @example\r\n * ```tsx\r\n * // With leading edge only\r\n * const throttledValue = useThrottle(value, 300, { leading: true, trailing: false });\r\n * ```\r\n *\r\n * @example\r\n * ```tsx\r\n * // With trailing edge only\r\n * const throttledValue = useThrottle(value, 300, { leading: false, trailing: true });\r\n * ```\r\n */\r\nexport function useThrottle<T>(\r\n value: T,\r\n delay: number = 500,\r\n options: UseThrottleOptions = {}\r\n): T {\r\n const { leading = true, trailing = true } = options;\r\n\r\n // Throttle is implemented using debounce with maxWait set to delay\r\n return useDebounce(value, delay, {\r\n leading,\r\n maxWait: delay,\r\n trailing,\r\n });\r\n}\r\n"],"mappings":";AAAA,SAAS,mBAA4C;AAwD9C,SAAS,YACd,OACA,QAAgB,KAChB,UAA8B,CAAC,GAC5B;AACH,QAAM,EAAE,UAAU,MAAM,WAAW,KAAK,IAAI;AAG5C,SAAO,YAAY,OAAO,OAAO;AAAA,IAC/B;AAAA,IACA,SAAS;AAAA,IACT;AAAA,EACF,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../src/useThrottle.ts"],"sourcesContent":["import { useDebounce, type UseDebounceOptions } from \"@usefy/use-debounce\";\r\n\r\n/**\r\n * Options for useThrottle hook\r\n */\r\nexport interface UseThrottleOptions {\r\n /**\r\n * Whether to update the throttled value on the leading edge\r\n * @default true\r\n */\r\n leading?: boolean;\r\n /**\r\n * Whether to update the throttled value on the trailing edge\r\n * @default true\r\n */\r\n trailing?: boolean;\r\n}\r\n\r\n/**\r\n * Throttles a value by limiting updates to at most once per specified interval.\r\n * This is implemented using useDebounce with maxWait set to the interval.\r\n * Useful for scroll events and resize handlers.\r\n *\r\n * @template T - The type of the value to throttle\r\n * @param value - The value to throttle\r\n * @param delay - The interval in milliseconds (default: 500ms)\r\n * @param options - Additional options for controlling throttle behavior\r\n * @returns The throttled value\r\n *\r\n * @example\r\n * ```tsx\r\n * function ScrollComponent() {\r\n * const [scrollY, setScrollY] = useState(0);\r\n * const throttledScrollY = useThrottle(scrollY, 100);\r\n *\r\n * useEffect(() => {\r\n * const handleScroll = () => setScrollY(window.scrollY);\r\n * window.addEventListener(\"scroll\", handleScroll);\r\n * return () => window.removeEventListener(\"scroll\", handleScroll);\r\n * }, []);\r\n *\r\n * return <div>Scroll Y: {throttledScrollY}</div>;\r\n * }\r\n * ```\r\n *\r\n * @example\r\n * ```tsx\r\n * // With leading edge only\r\n * const throttledValue = useThrottle(value, 300, { leading: true, trailing: false });\r\n * ```\r\n *\r\n * @example\r\n * ```tsx\r\n * // With trailing edge only\r\n * const throttledValue = useThrottle(value, 300, { leading: false, trailing: true });\r\n * ```\r\n */\r\nexport function useThrottle<T>(\r\n value: T,\r\n delay: number = 500,\r\n options: UseThrottleOptions = {}\r\n): T {\r\n const { leading = true, trailing = true } = options;\r\n\r\n // Throttle is implemented using debounce with maxWait set to delay\r\n return useDebounce(value, delay, {\r\n leading,\r\n maxWait: delay,\r\n trailing,\r\n });\r\n}\r\n"],"mappings":";AAAA,SAAS,mBAA4C;AAyD9C,SAAS,YACd,OACA,QAAgB,KAChB,UAA8B,CAAC,GAC5B;AACH,QAAM,EAAE,UAAU,MAAM,WAAW,KAAK,IAAI;AAG5C,SAAO,YAAY,OAAO,OAAO;AAAA,IAC/B;AAAA,IACA,SAAS;AAAA,IACT;AAAA,EACF,CAAC;AACH;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usefy/use-throttle",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "A React hook for throttling values",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -17,7 +17,7 @@
17
17
  ],
18
18
  "sideEffects": false,
19
19
  "dependencies": {
20
- "@usefy/use-debounce": "0.0.2"
20
+ "@usefy/use-debounce": "0.0.3"
21
21
  },
22
22
  "peerDependencies": {
23
23
  "react": "^18.0.0 || ^19.0.0"