After creating a store and authreducer, everything was working as expected. However, when I added the useSelector
in app.js, an error occurred:
ERROR Error: could not find react-redux context value; please ensure the component is wrapped in a
<Provider>
(Interestingly, using useSelector
in other files did not cause any errors.)
https://i.stack.imgur.com/y0sFG.png
import { ApolloClient, ApolloProvider } from "@apollo/client";
import { Provider, useSelector } from "react-redux";
import Navigation from "./navigation";
import Navigation2 from "./navigation2";
import { store } from "./src/Redux/store";
import InMemoryCacheFct from "./src/apolloClient/InMemoryCache";
export default function App() {
// The error occurs when this line is added, even though it works in other files
const user = useSelector(state => state.auth.isAuthenticated);
const client = new ApolloClient({
uri: ".......serverUrl",
cache: InMemoryCacheFct(),
queryDeduplication: true,
});
return (
<ApolloProvider client={client}>
<Provider store={store}>
{user ? <Navigation /> : <Navigation2 />}
</Provider>
</ApolloProvider>
);
}