Whenever I run my app through snack I keep getting this error: React Hook useEffect has an unnecessary dependency: Navigator. Either exclude it or remove the dependency array. Outer scope values like 'Navigator' aren't valid dependencies because mutating them doesn't re-render the component. (react-hooks/exhaustive-deps)
I tried looking on the web for fixes and tried reinstalling some packages but nothing would work.
The code related to the error is here:
export default function App() {
const [image, setImage] = useState(null);
useEffect(() => {
if (image != null){
const formData = new FormData();
formData.append('image', {
uri: image,
name: 'image.jpg',
type: 'image/jpeg',
});
fetch('http://192.168.1.75:8000/classify', {
method: 'POST',
body: formData,
headers: {
'Content-Type': 'multipart/form-data',
},
})
.then((response) => response.json())
.then((data) => {
Navigator.navigate('Detail', { disease: data });
})
.catch((error) => {
console.error(error);
});
}
}, [image, Navigator])
I tried to reinstall packages but that didnt work. I tried running it through my phone but that didnt work either I tried deleting code bit by bit but would still result in the error
Hey:) The useEffect hook should only include dependencies that are used within the effect itself. The Navigator variable should not be included in the dependency array because it is a global object and changing it does not cause the component to be re-rendered.
To solve this problem, you can remove Navigator from the dependency array:
In the HomeScreen function, instead of navigation={props.navigation} there should be navigation={navigation}.
Change "Navigator.navigate('Detail', { disease: data }) to navigation.navigate('Detail', { disease: data })".
In the "useEffect" function you are missing a dependency in the dependency array. Add "image" to this array.
Try updating @ui-kitten/components to the latest version that supports your version of React Native and Expo.
Updated answer: Judging by the logs, your project requires a version of @react-navigation/native at least 5.5.1, but it also requires a version of @react-navigation/native at least 6.0.0 for @react-navigation/stack. To resolve this conflict you need to update the @react-navigation/native version in your project to 6.x.x.
Enter the command in the terminal:
And
To update all dependencies If an error appears like the one I had at first: "CommandError: It looks like you're trying to use web support but don't have the required dependencies installed.
Please install react-native-web@~0.19.6, [email protected] by running:
npx expo install react-native-web@~0.19.6 [email protected]
If you're not using web, please ensure you remove the "web" string from the platforms array in the project Expo config." Then install the dependencies to support the web platform:
package.json: