Skip to content

Commit 2f33c85

Browse files
committed
Mark connect as deprecated
1 parent 97d4461 commit 2f33c85

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

src/components/connect.tsx

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ export interface ConnectOptions<
249249
}
250250

251251
/**
252+
253+
*
252254
* Connects a React component to a Redux store.
253255
*
254256
* - Without arguments, just wraps the component, without changing the behavior / props
@@ -415,6 +417,16 @@ export interface Connect<DefaultState = unknown> {
415417
let hasWarnedAboutDeprecatedPureOption = false
416418

417419
/**
420+
* @deprecated
421+
*
422+
* **We recommend using the `useSelector` and `useDispatch` hooks instead.**
423+
* See https://react-redux.js.org/api/hooks
424+
*
425+
* If you need to use `connect` without this visual deprecation warning,
426+
* import `legacy_connect` instead:
427+
*
428+
* `import { legacy_connect as connect } from 'react-redux'`
429+
*
418430
* Connects a React component to a Redux store.
419431
*
420432
* - Without arguments, just wraps the component, without changing the behavior / props
@@ -434,7 +446,7 @@ let hasWarnedAboutDeprecatedPureOption = false
434446
* @param options Options for configuring the connection
435447
*
436448
*/
437-
function connect<
449+
function _connect<
438450
TStateProps = {},
439451
TDispatchProps = {},
440452
TOwnProps = {},
@@ -810,4 +822,26 @@ function connect<
810822
return wrapWithConnect
811823
}
812824

813-
export default connect as Connect
825+
/**
826+
* * @deprecated
827+
*
828+
* **We recommend using the `useSelector` and `useDispatch` hooks instead.**
829+
* See https://react-redux.js.org/api/hooks
830+
*
831+
* If you need to use `connect` without this visual deprecation warning,
832+
* import `legacy_connect` instead:
833+
*
834+
* `import { legacy_connect as connect } from 'react-redux'`
835+
*/
836+
export const connect: Connect = _connect as Connect
837+
838+
interface LegacyConnect extends Connect {}
839+
840+
/**
841+
* Connects a React component to a Redux store. Same as `connect` but without
842+
* the deprecation warning.
843+
*
844+
* **We recommend using the `useSelector` and `useDispatch` hooks instead.**
845+
* See https://react-redux.js.org/api/hooks
846+
*/
847+
export const legacy_connect: Connect = _connect as Connect

src/exports.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import connect from './components/connect'
1+
import { connect, legacy_connect } from './components/connect'
22
export type {
33
Connect,
44
ConnectProps,
@@ -48,4 +48,4 @@ export * from './types'
4848
*/
4949
const batch = defaultNoopBatch
5050

51-
export { Provider, batch, connect, shallowEqual }
51+
export { Provider, batch, connect, legacy_connect, shallowEqual }

src/index-rsc.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export {
2323
throwNotSupportedError as Provider,
2424
throwNotSupportedError as batch,
2525
throwNotSupportedError as connect,
26+
throwNotSupportedError as legacy_connect,
2627
throwNotSupportedError as createDispatchHook,
2728
throwNotSupportedError as createSelectorHook,
2829
throwNotSupportedError as createStoreHook,

0 commit comments

Comments
 (0)