|
1 | 1 | import hoistStatics from 'hoist-non-react-statics'
|
2 |
| -import invariant from 'invariant' |
3 | 2 | import React, { useContext, useMemo, useRef, useReducer } from 'react'
|
4 | 3 | import { isValidElementType, isContextConsumer } from 'react-is'
|
5 | 4 | import Subscription from '../utils/Subscription'
|
@@ -78,34 +77,40 @@ export default function connectAdvanced(
|
78 | 77 | ...connectOptions
|
79 | 78 | } = {}
|
80 | 79 | ) {
|
81 |
| - invariant( |
82 |
| - renderCountProp === undefined, |
83 |
| - `renderCountProp is removed. render counting is built into the latest React Dev Tools profiling extension` |
84 |
| - ) |
85 |
| - |
86 |
| - invariant( |
87 |
| - !withRef, |
88 |
| - 'withRef is removed. To access the wrapped instance, use a ref on the connected component' |
89 |
| - ) |
90 |
| - |
91 |
| - const customStoreWarningMessage = |
92 |
| - 'To use a custom Redux store for specific components, create a custom React context with ' + |
93 |
| - "React.createContext(), and pass the context object to React Redux's Provider and specific components" + |
94 |
| - ' like: <Provider context={MyContext}><ConnectedComponent context={MyContext} /></Provider>. ' + |
95 |
| - 'You may also pass a {context : MyContext} option to connect' |
96 |
| - |
97 |
| - invariant( |
98 |
| - storeKey === 'store', |
99 |
| - 'storeKey has been removed and does not do anything. ' + |
100 |
| - customStoreWarningMessage |
101 |
| - ) |
| 80 | + if (process.env.NODE_ENV !== 'production') { |
| 81 | + if (renderCountProp !== undefined) { |
| 82 | + throw new Error( |
| 83 | + `renderCountProp is removed. render counting is built into the latest React Dev Tools profiling extension` |
| 84 | + ) |
| 85 | + } |
| 86 | + if (withRef) { |
| 87 | + throw new Error( |
| 88 | + 'withRef is removed. To access the wrapped instance, use a ref on the connected component' |
| 89 | + ) |
| 90 | + } |
| 91 | + |
| 92 | + const customStoreWarningMessage = |
| 93 | + 'To use a custom Redux store for specific components, create a custom React context with ' + |
| 94 | + "React.createContext(), and pass the context object to React Redux's Provider and specific components" + |
| 95 | + ' like: <Provider context={MyContext}><ConnectedComponent context={MyContext} /></Provider>. ' + |
| 96 | + 'You may also pass a {context : MyContext} option to connect' |
| 97 | + |
| 98 | + if (storeKey !== 'store') { |
| 99 | + throw new Error( |
| 100 | + 'storeKey has been removed and does not do anything. ' + |
| 101 | + customStoreWarningMessage |
| 102 | + ) |
| 103 | + } |
| 104 | + } |
102 | 105 |
|
103 | 106 | const Context = context
|
104 | 107 |
|
105 | 108 | return function wrapWithConnect(WrappedComponent) {
|
106 |
| - if (process.env.NODE_ENV !== 'production') { |
107 |
| - invariant( |
108 |
| - isValidElementType(WrappedComponent), |
| 109 | + if ( |
| 110 | + process.env.NODE_ENV !== 'production' && |
| 111 | + !isValidElementType(WrappedComponent) |
| 112 | + ) { |
| 113 | + throw new Error( |
109 | 114 | `You must pass a component to the function returned by ` +
|
110 | 115 | `${methodName}. Instead received ${stringifyComponent(
|
111 | 116 | WrappedComponent
|
@@ -173,13 +178,18 @@ export default function connectAdvanced(
|
173 | 178 | const didStoreComeFromContext =
|
174 | 179 | Boolean(contextValue) && Boolean(contextValue.store)
|
175 | 180 |
|
176 |
| - invariant( |
177 |
| - didStoreComeFromProps || didStoreComeFromContext, |
178 |
| - `Could not find "store" in the context of ` + |
179 |
| - `"${displayName}". Either wrap the root component in a <Provider>, ` + |
180 |
| - `or pass a custom React context provider to <Provider> and the corresponding ` + |
181 |
| - `React context consumer to ${displayName} in connect options.` |
182 |
| - ) |
| 181 | + if ( |
| 182 | + process.env.NODE_ENV !== 'production' && |
| 183 | + !didStoreComeFromProps && |
| 184 | + !didStoreComeFromContext |
| 185 | + ) { |
| 186 | + throw new Error( |
| 187 | + `Could not find "store" in the context of ` + |
| 188 | + `"${displayName}". Either wrap the root component in a <Provider>, ` + |
| 189 | + `or pass a custom React context provider to <Provider> and the corresponding ` + |
| 190 | + `React context consumer to ${displayName} in connect options.` |
| 191 | + ) |
| 192 | + } |
183 | 193 |
|
184 | 194 | // Based on the previous check, one of these must be true
|
185 | 195 | const store = didStoreComeFromProps ? props.store : contextValue.store
|
|
0 commit comments