When I use React's Context API in my Expo React Native project get this warning:
Require cycles are allowed, but can result in uninitialized values. Consider refactoring to remove the need for a cycle.
Im creating a context in App.tsx:
import Start from "./start";
export const AppContext = React.createContext({
isLandscape: true,
});
export default function App() {
return (
<AppContext.Provider value={{ isLandscape: false }}>
<Start />
</AppContext.Provider>
);
}
And in a Start.tsx component I'm using the context:
import { AppContext } from "./App"
export default function App() {
const context = React.useContext(AppContext);
console.log(context);
return (
<Text>Sutff</Text>
);
}
I looks like the warning is because App
imports Choose
which then imports the context from App
again. Require cycles are allowed, but can result in uninitialized values. Consider refactoring to remove the need for a cycle
However isn't this how the Context API is supposed to be used? How do people normally deal with this when using the Context API in React Native?