Created
November 2, 2023 14:46
-
-
Save GalindoSVQ/4d367b2855fee91250dae298657a6113 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import * as React from 'react'; | |
| export default function usePrevious(newValue: string) { | |
| const [value, setValue] = React.useState<string>(newValue); | |
| const [preValue, setPreValue] = React.useState<string | null>(null); | |
| if (newValue !== value) { | |
| setPreValue(value); | |
| setValue(newValue); | |
| } | |
| return preValue; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Stackblitz link: https://stackblitz.com/edit/vitejs-vite-hbfnm1?file=src%2FusePrevious.ts