useStore.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.createStoreHook = createStoreHook;
  4. exports.useStore = void 0;
  5. var _Context = require("../components/Context");
  6. var _useReduxContext = require("./useReduxContext");
  7. /**
  8. * Hook factory, which creates a `useStore` hook bound to a given context.
  9. *
  10. * @param {React.Context} [context=ReactReduxContext] Context passed to your `<Provider>`.
  11. * @returns {Function} A `useStore` hook bound to the specified context.
  12. */
  13. function createStoreHook(context = _Context.ReactReduxContext) {
  14. const useReduxContext = // @ts-ignore
  15. context === _Context.ReactReduxContext ? _useReduxContext.useReduxContext : // @ts-ignore
  16. (0, _useReduxContext.createReduxContextHook)(context);
  17. return function useStore() {
  18. const {
  19. store
  20. } = useReduxContext(); // @ts-ignore
  21. return store;
  22. };
  23. }
  24. /**
  25. * A hook to access the redux store.
  26. *
  27. * @returns {any} the redux store
  28. *
  29. * @example
  30. *
  31. * import React from 'react'
  32. * import { useStore } from 'react-redux'
  33. *
  34. * export const ExampleComponent = () => {
  35. * const store = useStore()
  36. * return <div>{store.getState()}</div>
  37. * }
  38. */
  39. const useStore = /*#__PURE__*/createStoreHook();
  40. exports.useStore = useStore;