You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

28 lines
856 B

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