|
1 |
| -import { useReducer, useRef, useEffect, useMemo, useLayoutEffect } from 'react' |
| 1 | +import { |
| 2 | + useReducer, |
| 3 | + useRef, |
| 4 | + useEffect, |
| 5 | + useMemo, |
| 6 | + useLayoutEffect, |
| 7 | + useContext |
| 8 | +} from 'react' |
2 | 9 | import invariant from 'invariant'
|
3 |
| -import { useReduxContext } from './useReduxContext' |
| 10 | +import { useReduxContext as useDefaultReduxContext } from './useReduxContext' |
4 | 11 | import Subscription from '../utils/Subscription'
|
5 | 12 | import { ReactReduxContext } from '../components/Context'
|
6 | 13 |
|
@@ -46,10 +53,14 @@ function useSelectorWithStoreAndSubscription(
|
46 | 53 | selectedState = latestSelectedState.current
|
47 | 54 | }
|
48 | 55 | } catch (err) {
|
49 |
| - let errorMessage = `An error occured while selecting the store state: ${err.message}.` |
| 56 | + let errorMessage = `An error occured while selecting the store state: ${ |
| 57 | + err.message |
| 58 | + }.` |
50 | 59 |
|
51 | 60 | if (latestSubscriptionCallbackError.current) {
|
52 |
| - errorMessage += `\nThe error may be correlated with this previous error:\n${latestSubscriptionCallbackError.current.stack}\n\nOriginal stack trace:` |
| 61 | + errorMessage += `\nThe error may be correlated with this previous error:\n${ |
| 62 | + latestSubscriptionCallbackError.current.stack |
| 63 | + }\n\nOriginal stack trace:` |
53 | 64 | }
|
54 | 65 |
|
55 | 66 | throw new Error(errorMessage)
|
@@ -100,10 +111,14 @@ function useSelectorWithStoreAndSubscription(
|
100 | 111 | * @returns {Function} A `useSelector` hook bound to the specified context.
|
101 | 112 | */
|
102 | 113 | export function createSelectorHook(context = ReactReduxContext) {
|
| 114 | + const useReduxContext = |
| 115 | + context === ReactReduxContext |
| 116 | + ? useDefaultReduxContext |
| 117 | + : () => useContext(context) |
103 | 118 | return function useSelector(selector, equalityFn = refEquality) {
|
104 | 119 | invariant(selector, `You must pass a selector to useSelectors`)
|
105 | 120 |
|
106 |
| - const { store, subscription: contextSub } = useReduxContext(context) |
| 121 | + const { store, subscription: contextSub } = useReduxContext() |
107 | 122 |
|
108 | 123 | return useSelectorWithStoreAndSubscription(
|
109 | 124 | selector,
|
|
0 commit comments