UNPKG

863 BSource Map (JSON)View Raw
1{"version":3,"sources":["usePreviousValue.js"],"names":["usePreviousValue","value","prevValue","current","undefined"],"mappings":";;;;;;;AAAA;;AAKA,IAAMA,gBAAgB,GAAG,SAAnBA,gBAAmB,CAACC,KAAD,EAAW;AAClC,MAAMC,SAAS,GAAG,oBAAlB;AAEA,wBAAU,YAAM;AACdA,IAAAA,SAAS,CAACC,OAAV,GAAoBF,KAApB;AAEA,WAAO,YAAM;AACXC,MAAAA,SAAS,CAACC,OAAV,GAAoBC,SAApB;AACD,KAFD;AAGD,GAND;AAQA,SAAOF,SAAS,CAACC,OAAjB;AACD,CAZD;;eAceH,gB","sourcesContent":["import { useEffect, useRef } from 'react';\n\n/**\n * On each render returns the previous value of the given variable/constant.\n */\nconst usePreviousValue = (value) => {\n const prevValue = useRef();\n\n useEffect(() => {\n prevValue.current = value;\n\n return () => {\n prevValue.current = undefined;\n };\n });\n\n return prevValue.current;\n};\n\nexport default usePreviousValue;\n"],"file":"usePreviousValue.js"}
\No newline at end of file