useSelector is used to obtain information from the state.
const state = useSelector(state => state);
The code snippet above basically makes the useSelector hook convert the state into an object that can be accessed with the variable that holds useSelector, in this case, “state”.
One idea is that you can destructure the state, for example, like this:
const { msgError } = useSelector(state => state);
It is important NOT TO FORGET to import the hook…
import { useSelector } from 'react-redux';
It is also important to note that even if we don’t trigger a change in a form with a button, for example, just changing the state will automatically trigger the action. This is normal; that’s how React works.