diff --git a/package-lock.json b/package-lock.json
index 3e471d59e..3c4df4c6a 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -6250,6 +6250,7 @@
"version": "2.2.4",
"resolved": "https://registry.npmjs.org/invariant/-/invariant-2.2.4.tgz",
"integrity": "sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA==",
+ "dev": true,
"requires": {
"loose-envify": "^1.0.0"
}
diff --git a/package.json b/package.json
index 96d9471c2..92662f838 100644
--- a/package.json
+++ b/package.json
@@ -50,7 +50,6 @@
"dependencies": {
"@babel/runtime": "^7.5.5",
"hoist-non-react-statics": "^3.3.0",
- "invariant": "^2.2.4",
"loose-envify": "^1.4.0",
"prop-types": "^15.7.2",
"react-is": "^16.9.0"
diff --git a/src/components/connectAdvanced.js b/src/components/connectAdvanced.js
index 627ac07e1..ec9deefc9 100644
--- a/src/components/connectAdvanced.js
+++ b/src/components/connectAdvanced.js
@@ -1,5 +1,4 @@
import hoistStatics from 'hoist-non-react-statics'
-import invariant from 'invariant'
import React, { useContext, useMemo, useRef, useReducer } from 'react'
import { isValidElementType, isContextConsumer } from 'react-is'
import Subscription from '../utils/Subscription'
@@ -78,34 +77,40 @@ export default function connectAdvanced(
...connectOptions
} = {}
) {
- invariant(
- renderCountProp === undefined,
- `renderCountProp is removed. render counting is built into the latest React Dev Tools profiling extension`
- )
-
- invariant(
- !withRef,
- 'withRef is removed. To access the wrapped instance, use a ref on the connected component'
- )
-
- const customStoreWarningMessage =
- 'To use a custom Redux store for specific components, create a custom React context with ' +
- "React.createContext(), and pass the context object to React Redux's Provider and specific components" +
- ' like: . ' +
- 'You may also pass a {context : MyContext} option to connect'
-
- invariant(
- storeKey === 'store',
- 'storeKey has been removed and does not do anything. ' +
- customStoreWarningMessage
- )
+ if (process.env.NODE_ENV !== 'production') {
+ if (renderCountProp !== undefined) {
+ throw new Error(
+ `renderCountProp is removed. render counting is built into the latest React Dev Tools profiling extension`
+ )
+ }
+ if (withRef) {
+ throw new Error(
+ 'withRef is removed. To access the wrapped instance, use a ref on the connected component'
+ )
+ }
+
+ const customStoreWarningMessage =
+ 'To use a custom Redux store for specific components, create a custom React context with ' +
+ "React.createContext(), and pass the context object to React Redux's Provider and specific components" +
+ ' like: . ' +
+ 'You may also pass a {context : MyContext} option to connect'
+
+ if (storeKey !== 'store') {
+ throw new Error(
+ 'storeKey has been removed and does not do anything. ' +
+ customStoreWarningMessage
+ )
+ }
+ }
const Context = context
return function wrapWithConnect(WrappedComponent) {
- if (process.env.NODE_ENV !== 'production') {
- invariant(
- isValidElementType(WrappedComponent),
+ if (
+ process.env.NODE_ENV !== 'production' &&
+ !isValidElementType(WrappedComponent)
+ ) {
+ throw new Error(
`You must pass a component to the function returned by ` +
`${methodName}. Instead received ${stringifyComponent(
WrappedComponent
@@ -173,13 +178,18 @@ export default function connectAdvanced(
const didStoreComeFromContext =
Boolean(contextValue) && Boolean(contextValue.store)
- invariant(
- didStoreComeFromProps || didStoreComeFromContext,
- `Could not find "store" in the context of ` +
- `"${displayName}". Either wrap the root component in a , ` +
- `or pass a custom React context provider to and the corresponding ` +
- `React context consumer to ${displayName} in connect options.`
- )
+ if (
+ process.env.NODE_ENV !== 'production' &&
+ !didStoreComeFromProps &&
+ !didStoreComeFromContext
+ ) {
+ throw new Error(
+ `Could not find "store" in the context of ` +
+ `"${displayName}". Either wrap the root component in a , ` +
+ `or pass a custom React context provider to and the corresponding ` +
+ `React context consumer to ${displayName} in connect options.`
+ )
+ }
// Based on the previous check, one of these must be true
const store = didStoreComeFromProps ? props.store : contextValue.store
diff --git a/src/hooks/useReduxContext.js b/src/hooks/useReduxContext.js
index 903a11c44..70ea903df 100644
--- a/src/hooks/useReduxContext.js
+++ b/src/hooks/useReduxContext.js
@@ -1,5 +1,4 @@
import { useContext } from 'react'
-import invariant from 'invariant'
import { ReactReduxContext } from '../components/Context'
/**
@@ -21,10 +20,11 @@ import { ReactReduxContext } from '../components/Context'
export function useReduxContext() {
const contextValue = useContext(ReactReduxContext)
- invariant(
- contextValue,
- 'could not find react-redux context value; please ensure the component is wrapped in a '
- )
+ if (process.env.NODE_ENV !== 'production' && !contextValue) {
+ throw new Error(
+ 'could not find react-redux context value; please ensure the component is wrapped in a '
+ )
+ }
return contextValue
}
diff --git a/src/hooks/useSelector.js b/src/hooks/useSelector.js
index 2e8c8b877..e923aef28 100644
--- a/src/hooks/useSelector.js
+++ b/src/hooks/useSelector.js
@@ -1,5 +1,4 @@
import { useReducer, useRef, useMemo, useContext } from 'react'
-import invariant from 'invariant'
import { useReduxContext as useDefaultReduxContext } from './useReduxContext'
import Subscription from '../utils/Subscription'
import { useIsomorphicLayoutEffect } from '../utils/useIsomorphicLayoutEffect'
@@ -95,8 +94,9 @@ export function createSelectorHook(context = ReactReduxContext) {
? useDefaultReduxContext
: () => useContext(context)
return function useSelector(selector, equalityFn = refEquality) {
- invariant(selector, `You must pass a selector to useSelectors`)
-
+ if (process.env.NODE_ENV !== 'production' && !selector) {
+ throw new Error(`You must pass a selector to useSelectors`)
+ }
const { store, subscription: contextSub } = useReduxContext()
return useSelectorWithStoreAndSubscription(