The screenshot below is taken from the Maximilian Schwarzmüller’s Udemy Course "React – The Complete Guide (incl Hooks, React Router, Redux)"
When using useSelector to access some part of the state, it is not obvious where the state is being passed in. In the screenshot below, Max executes useSelector to access the cartIsVisible method of the ui reducer – but how does he get access to the state itself? Since the useSelector is just a hook taken from react-redux and there is nothing else passed in, how does he have access to state? When I tried to console.log(state) it shows an error that state is not defined.
>Solution :
If you look at the index.js you should see a <Provider wrapping the App component as so
<Provider store={store}>
<App />
</Provider>
The useSelector hook gets the state from the redux store sent in the wrapper <Provider component.
The Provider makes the Redux store available to the component hierarchy below.
