{"version":3,"file":"syncedstore-react.modern.mjs","sources":["../src/index.ts"],"sourcesContent":["import * as reactive from \"@reactivedata/react\";\nimport * as syncedstore from \"@syncedstore/core\";\nimport type * as React from \"react\";\n\n/**\n * React hook to enable smart Reactive rerendering of your functional component.\n *\n * The usage of the return value is automatically tracked.\n * The component where you use this hook is then rerendered automatically if any of the\n * used values change.\n *\n * e.g.:\n *\n * // Store setup:\n * const globalStore = SyncedStore({ people: [] });\n * globalStore.people.push({ name: \"Alice\" });\n * globalStore.people.push({ name: \"Bob\" });\n *\n * // In your component:\n * const store = useSyncedStore(globalStore);\n * <div>{store.people[1].name}</div>\n *\n * Now, your component only rerenders when Bob's name changes\n *  (or if the second element of the array changes)\n */\nexport function useSyncedStore<T>(syncedObject: T, deps?: React.DependencyList) {\n  if (!syncedstore.getYjsValue(syncedObject)) {\n    throw new Error(\"syncedObject passed to useSyncedStore is not a SyncedStore Store or internal data type.\");\n  }\n  // useSyncedStore is just a wrapper for useReactive\n  return reactive.useReactive(syncedObject, deps);\n}\n\nexport function useSyncedStores<T extends any[]>(syncedObjects: T, deps?: React.DependencyList) {\n  return reactive.useReactives(syncedObjects, deps);\n}\n"],"names":["useSyncedStore","syncedObject","deps","syncedstore","getYjsValue","Error","reactive","useReactive","useSyncedStores","syncedObjects","useReactives"],"mappings":";;;AAIA;;;;;;;;;;;;;;;;;;;;AAoBG;AACa,SAAAA,cAAc,CAAIC,YAAe,EAAEC,IAA2B,EAAA;AAC5E,EAAA,IAAI,CAACC,WAAW,CAACC,WAAW,CAACH,YAAY,CAAC,EAAE;AAC1C,IAAA,MAAM,IAAII,KAAK,CAAC,yFAAyF,CAAC,CAAA;AAC3G,GAAA;AACD;AACA,EAAA,OAAOC,QAAQ,CAACC,WAAW,CAACN,YAAY,EAAEC,IAAI,CAAC,CAAA;AACjD,CAAA;AAEgB,SAAAM,eAAe,CAAkBC,aAAgB,EAAEP,IAA2B,EAAA;AAC5F,EAAA,OAAOI,QAAQ,CAACI,YAAY,CAACD,aAAa,EAAEP,IAAI,CAAC,CAAA;AACnD;;;;"}