useReduxContext.js 927 B

12345678910111213141516171819202122232425262728293031323334
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.useReduxContext = useReduxContext;
  4. var _react = require("react");
  5. var _Context = require("../components/Context");
  6. /**
  7. * A hook to access the value of the `ReactReduxContext`. This is a low-level
  8. * hook that you should usually not need to call directly.
  9. *
  10. * @returns {any} the value of the `ReactReduxContext`
  11. *
  12. * @example
  13. *
  14. * import React from 'react'
  15. * import { useReduxContext } from 'react-redux'
  16. *
  17. * export const CounterComponent = ({ value }) => {
  18. * const { store } = useReduxContext()
  19. * return <div>{store.getState()}</div>
  20. * }
  21. */
  22. function useReduxContext() {
  23. var contextValue = (0, _react.useContext)(_Context.ReactReduxContext);
  24. if (process.env.NODE_ENV !== 'production' && !contextValue) {
  25. throw new Error('could not find react-redux context value; please ensure the component is wrapped in a <Provider>');
  26. }
  27. return contextValue;
  28. }