Package Exports
- @better-typed/react-performance-hooks
- @better-typed/react-performance-hooks/dist/index.cjs.js
- @better-typed/react-performance-hooks/dist/index.esm.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@better-typed/react-performance-hooks) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
React Performance Hooks
Debounce and throttle your functions to gain performance boost!
Features
- 🚀 Simple, fast and light
- 🏭 Debounce and Throttle
- 🪗 Lifecycle events handling
Install
npm install --save @better-typed/react-performance-hooks
or
yarn add @better-typed/react-performance-hooks
useDebounce
This hook allows debouncing of the given function.
import React from "react";
import { useDebounce } from "@better-typed/react-performance-hooks";
const MyComponent: React.FC = ({ delay }) => {
const {debounce, reset, active} = useDebounce(delay)
// Standard usage
const onTyping = () => {
debounce(() => {
// debounced logic
})
}
// Dynamic delay value
const onTypingDynamic = (value: string, customDelay: number) => {
debounce(() => {
// debounced logic
}, customDelay)
}
return (
// ...
)
}
useThrottle
This hook allows debouncing of the given function.
import React from "react";
import { useThrottle } from "@better-typed/react-performance-hooks";
const MyComponent: React.FC = ({ delay }) => {
const {throttle, reset, active} = useThrottle(delay)
// Standard usage
const onScroll = () => {
throttle(() => {
// throttle logic
})
}
// Dynamic delay value
const onScrollDynamic = (value: string, customDelay: number) => {
throttle(() => {
// throttle logic
}, customDelay)
}
return (
// ...
)
}