UNPKG

@liveblocks/react-ui

Version:

A set of React pre-built components for the Liveblocks products. Liveblocks is the all-in-one toolkit to build collaborative products like Figma, Notion, and more.

1 lines 698 B
{"version":3,"file":"use-initial.cjs","sources":["../../src/utils/use-initial.ts"],"sourcesContent":["import { useState } from \"react\";\n\n/**\n * \"Freezes\" a given value, so that it will return the same value/instance on\n * each subsequent render. This can be used to freeze \"initial\" values for\n * custom hooks, much like how `useState(initialState)` or\n * `useRef(initialValue)` works.\n */\nexport function useInitial<T>(value: T | (() => T)): T {\n const [initialValue] = useState(value);\n\n return initialValue;\n}\n"],"names":["useState"],"mappings":";;;;AAQO,SAAS,WAAc,KAAyB,EAAA;AACrD,EAAA,MAAM,CAAC,YAAY,CAAI,GAAAA,cAAA,CAAS,KAAK,CAAA,CAAA;AAErC,EAAO,OAAA,YAAA,CAAA;AACT;;;;"}