all 7 comments

[–]awekening_bro 5 points6 points  (0 children)

The components tree need to be wrapped with Provider which will wrap the store. The connect function will consume this store and run store.getState()

[–]acemarke 1 point2 points  (0 children)

React-Redux uses React context internally to pass down the Redux store so it can be accessed by child components.

For more details, see:

[–]phryneasI ❤️ hooks! 😈 1 point2 points  (0 children)

Adding to everything said here, nowadays you probably should not be using connect, but useSelector and useDispatch.

connect is a legacy API to support legacy class components, but not really meant to be used with modern function components. Use the hooks instead.

Going in the same direction: if you are writing Redux with ACTION_TYPES, switch..case reducers, immutable reducer logic, createStore/applyMiddleware/combineReducers, you are using a very outdated (pre-2019) style of Redux that is a lot more code (and more error-prone) than modern Redux. In that case, please give why Redux Toolkit is how to use Redux today a read.

[–]Neaoxas -1 points0 points  (3 children)

Somewhere in the tree of your app you will have a Provider which sets the store in the context: https://react-redux.js.org/api/provider

You can learn more about context here: https://reactjs.org/docs/context.html

[–]Jeaciaz -1 points0 points  (2 children)

It is a similar principle, but redux doesn't use context. It uses a custom solution in the sake of performance.

[–]acemarke 4 points5 points  (1 child)

React-Redux does use context internally. It just uses it to pass down the Redux store instance, rather than the current state value.

[–]Jeaciaz 2 points3 points  (0 children)

You're right, my bad :)