UNPKG

@open-condo/miniapp-utils

Version:

A set of helper functions / components / hooks used to build new condo apps fast

1 lines 950 B
{"version":3,"sources":["../../src/hooks/usePrevious.ts"],"sourcesContent":["// SRC: https://github.com/streamich/react-use/blob/master/src/usePrevious.ts\n\nimport { useEffect, useRef } from 'react'\n\n/**\n * Returns previous state value, useful for diff comparison\n * @example\n * const [count, setCount] = useState(0)\n * const prevCount = usePrevious(value)\n *\n * return (\n * <button onClick={() => setValue(current => current + 1)}>\n * Diff: {count - prevCount}\n * </button>\n * )\n */\nexport function usePrevious<T> (state: T): T | undefined {\n const ref = useRef<T>()\n\n // Runs all the times, but after rendering, so ref.current update happens after return\n useEffect(() => {\n ref.current = state\n })\n\n return ref.current\n}\n"],"mappings":";AAEA,SAAS,WAAW,cAAc;AAc3B,SAAS,YAAgB,OAAyB;AACrD,QAAM,MAAM,OAAU;AAGtB,YAAU,MAAM;AACZ,QAAI,UAAU;AAAA,EAClB,CAAC;AAED,SAAO,IAAI;AACf;","names":[]}