{"version":3,"file":"statemanjs-react.mjs","sources":["../../src/statemanjs-react/useStatemanjs.tsx"],"sourcesContent":["import { useState, useEffect } from \"react\";\nimport type {\n    StatemanjsAPI,\n    SubscriptionOptions,\n    StatemanjsComputedAPI,\n} from \"../statemanjs/index\";\n\n/**\n * Make the react component observe the statemanjs.\n * In the options, you can specify information about the observer,\n * as well as specify the condition under which the observer will be notified.\n *\n * @param statemanjs Statemanjs to observe.\n * @param subscriptionOptions Additional information and notification condition.\n * @returns Reactive state.\n */\nfunction useStatemanjs<T>(\n    statemanjs: StatemanjsAPI<T> | StatemanjsComputedAPI<T>,\n    subscriptionOptions: SubscriptionOptions<T> = {},\n): T {\n    const [_, forceRender] = useState({});\n\n    useEffect(() => {\n        return statemanjs.subscribe(() => {\n            forceRender({});\n        }, subscriptionOptions);\n    }, [statemanjs, subscriptionOptions]);\n\n    return statemanjs.get();\n}\n\nexport { useStatemanjs };\n"],"names":["useStatemanjs","statemanjs","subscriptionOptions","_","forceRender","useState","useEffect","subscribe","get"],"mappings":"gDAgBA,SAASA,EACLC,EACAC,EAA8C,IAE9C,MAAOC,EAAGC,GAAeC,EAAS,CAAE,GAQpC,OANAC,GAAU,IACCL,EAAWM,WAAU,KACxBH,EAAY,CAAE,EAAA,GACfF,IACJ,CAACD,EAAYC,IAETD,EAAWO,KACtB"}