@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 • 1.01 kB
Source Map (JSON)
{"version":3,"file":"use-rerender.cjs","sources":["../../src/utils/use-rerender.ts"],"sourcesContent":["import { useReducer } from \"react\";\n\n/**\n * Trigger a re-render programmatically, without changing the component's\n * state.\n *\n * @example\n * const rerender = useRerender();\n *\n * return (\n * <button onClick={rerender}>\n * {Math.random()}\n * </button>\n * )\n */\nexport function useRerender(): [() => void, number] {\n const [key, update] = useReducer(\n // This implementation works by incrementing a hidden counter value that is\n // never consumed. Simply incrementing the counter changes the component's\n // state and, thus, trigger a re-render.\n (key: number): number => key + 1,\n 0\n );\n return [update, key];\n}\n"],"names":["useReducer","key"],"mappings":";;;;AAeO,SAAS,WAAoC,GAAA;AAClD,EAAM,MAAA,CAAC,GAAK,EAAA,MAAM,CAAI,GAAAA,gBAAA;AAAA,IAIpB,CAACC,SAAwBA,IAAM,GAAA,CAAA;AAAA,IAC/B,CAAA;AAAA,GACF,CAAA;AACA,EAAO,OAAA,CAAC,QAAQ,GAAG,CAAA,CAAA;AACrB;;;;"}