import React, { useState } from 'react' import { type Meta } from '@storybook/react-vite' import Button from '../../components/Button/Button' import { usePrevious } from '..' import { DocsTemplate } from '../../../.storybook' export const Example = (): React.JSX.Element => { const [value, setValue] = useState(0) const previous = usePrevious(value) return (
Current Value: {value}
Previous Value: {previous?.toString()}
) } Example.storyName = 'usePrevious' Example.args = {} export default { title: 'Hooks/usePrevious', component: Example, parameters: { viewMode: 'docs', previewTabs: { canvas: { hidden: true }, }, docs: { page: () => ( <> usePrevious is a hook and will store the previous value of a given state. This can be a great tool to compare a current and previous value. An example might be using{' '} usePrevious to store the previous location pathname so that you can take an action if the pathname changes. , ]} noArgs /> ), }, }, } as Meta