--- title: usePrevious description: "`usePrevious` is a custom hook for obtaining the previous value." links: - source: https://github.com/yamada-ui/yamada-ui/tree/main/packages/react/src/hooks/use-previous - storybook: https://yamada-ui.github.io/yamada-ui?path=/story/hooks-useprevious--basic --- ```tsx const [flg, { toggle }] = useBoolean() const prevFlg = usePrevious(flg) return ( state: {String(flg)}, prev: {String(prevFlg)} ) ``` ## Usage ```tsx import { usePrevious } from "@yamada-ui/react" ``` ```tsx import { usePrevious } from "@/components/ui" ``` ```tsx import { usePrevious } from "@workspaces/ui" ``` ```tsx const [flg, { toggle }] = useBoolean() const prevFlg = usePrevious(flg) ```