{"version":3,"sources":["../../src/use-reactive/index.ts"],"sourcesContent":["import { useCreation } from '../use-creation'\nimport { isFunction } from '../utils/basic'\n\nimport type { create } from '@shined/reactive'\n\n// TODO: export from @shined/reactive\ninterface SnapshotOptions<StateSlice> {\n  sync?: boolean\n  isEqual?: (a: StateSlice, b: StateSlice) => boolean\n}\n\nexport type UseReactiveOptions<State> = SnapshotOptions<State> & { create: typeof create }\n\n/**\n * A React Hook that helps to use [Reactive](https://sheinsight.github.io/reactive) in React with ease.\n *\n * @deprecated will be removed in the future, maybe moved to `@shined/reactive`\n */\n/* v8 ignore next 24 */\nexport function useReactive<State extends object>(\n  initialState: State,\n  options: UseReactiveOptions<State>,\n): readonly [State, State] {\n  const store = useCreation(() => {\n    if (!isFunction(options.create)) {\n      throw new Error('Please provide the `create` function from `@shined/reactive`')\n    }\n\n    return options.create(initialState)\n  })\n\n  return [\n    store.useSnapshot({\n      sync: options.sync,\n      isEqual: options.isEqual,\n    }),\n    store.mutate,\n  ] as const\n}\n"],"names":["useReactive","initialState","options","store","useCreation","isFunction","create","Error","useSnapshot","sync","isEqual","mutate"],"mappings":";;;;+BAmBgBA;;;eAAAA;;;2BAnBY;qBACD;AAkBpB,SAASA,YACdC,YAAmB,EACnBC,OAAkC;IAElC,IAAMC,QAAQC,IAAAA,wBAAW,EAAC;QACxB,IAAI,CAACC,IAAAA,iBAAU,EAACH,QAAQI,MAAM,GAAG;YAC/B,MAAM,IAAIC,MAAM;QAClB;QAEA,OAAOL,QAAQI,MAAM,CAACL;IACxB;IAEA,OAAO;QACLE,MAAMK,WAAW,CAAC;YAChBC,MAAMP,QAAQO,IAAI;YAClBC,SAASR,QAAQQ,OAAO;QAC1B;QACAP,MAAMQ,MAAM;KACb;AACH"}