import React from 'react' import { type Meta } from '@storybook/react-vite' import Button from '../../components/Button/Button' import { debounce } from '../../services/HelperServiceTyped' import { DocsTemplate } from '../../../.storybook' export const Example = (): React.JSX.Element => { const [random, setRandom] = React.useState(0) const newNumber = () => { const newNumber = Math.round(Math.random() * 100) setRandom(newNumber) } return ( <>
There is a delay of 500ms after each button click
{random} ) } Example.storyName = 'debounce' export default { title: 'Helper Functions/debounce', component: Example, parameters: { viewMode: 'docs', previewTabs: { canvas: { hidden: true }, }, docs: { page: () => ( <> {return doesSomething()} debounce(anyFunction, yourDelay) // or debounce(() => {yourDelayedFunction()}, 500)`} description="Debounce is a function that delays a function's execution until after a specified amount of time has passed since the last time it was invoked. It accepts two parameters: the function to debounce and the number of milliseconds to delay the function for." infoBullets={[ debounce is used to prevent the function from being called too frequently, which can cause performance issues. , ]} noArgs /> ), }, }, } as Meta