{"version":3,"file":"ReduxProvider.cjs","names":["isAsyncStore","Provider"],"sources":["../../src/createReduxAsyncStore/ReduxProvider.tsx"],"sourcesContent":["import { cloneElement, useEffect, useState } from 'react';\nimport { Provider } from 'react-redux';\nimport { isAsyncStore } from './temp/createAsyncStore/isAsyncStore';\nimport type { Store } from '@reduxjs/toolkit';\nimport type { ReduxProviderProps, ReduxAsyncStore } from './types';\n\n/**\n * The `ReduxProvider` component wraps its children with the Redux `Provider` component,\n * ensuring that the async Redux store is ready before rendering the children. It also provides\n * a fallback UI that is displayed while the store is initializing.\n *\n * @param props - The props for the `ReduxProvider` component.\n * @param props.store - The async Redux store object or regular Redux store to be provided to the Redux context.\n * @param props.children - The React elements to be rendered inside the Redux `Provider` once the store is ready.\n * @param props.fallback - Optional fallback UI to be displayed while the Redux store is initializing. Defaults to an empty fragment.\n *\n * @returns A `Provider` component wrapping the children, or the fallback UI if the store is not ready.\n *\n * @example\n * // Example usage:\n * <ReduxProvider reduxStore={myReduxStore} fallback={<LoadingSpinner />}>\n *   <MyApp />\n * </ReduxProvider>\n */\nexport function ReduxProvider(props: ReduxProviderProps) {\n  const { store, children, fallback = <></> } = props;\n  const [ready, setReady] = useState<boolean>(!isAsyncStore(store));\n\n  useEffect(() => {\n    if (ready) return;\n      \n    (async () => {\n      const result = await (store as ReduxAsyncStore).isReady;\n      setReady(result);\n    })();\n  }, []);\n\n  return (\n    !ready ? cloneElement(fallback) : (\n      <Provider store={isAsyncStore(store) ? (store as ReduxAsyncStore).store : store as Store}>\n        {children}\n      </Provider>\n    )\n  );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAwBA,SAAgB,cAAc,OAA2B;CACvD,MAAM,EAAE,OAAO,UAAU,WAAW,iBAAA,GAAA,kBAAA,IAAA,CAAA,kBAAA,UAAA,CAAI,CAAA,MAAM;CAC9C,MAAM,CAAC,OAAO,aAAA,GAAA,MAAA,SAAA,CAA8B,CAACA,iEAAAA,aAAa,KAAK,CAAC;CAEhE,CAAA,GAAA,MAAA,UAAA,OAAgB;EACd,IAAI,OAAO;EAEX,CAAC,YAAY;GACX,MAAM,SAAS,MAAO,MAA0B;GAChD,SAAS,MAAM;EACjB,EAAA,CAAG;CACL,GAAG,CAAC,CAAC;CAEL,OACE,CAAC,SAAA,GAAA,MAAA,aAAA,CAAqB,QAAQ,IAC5B,iBAAA,GAAA,kBAAA,IAAA,CAACC,YAAAA,UAAD;EAAU,OAAOD,iEAAAA,aAAa,KAAK,IAAK,MAA0B,QAAQ;EACvE;CACO,CAAA;AAGhB"}