I want to resolve all warnings in my project but i don't know what dependencies should i include inside the dependency array. Below i share the code:
import React, { useState, useEffect } from 'react';
import { Redirect } from 'react-router-dom';
import Layout from '../components/Layout';
import { getPicture, getAlbums, updatePicture } from './ApiAdmin';
const UpdatePicture = ({ match }) => {
...
const init = (pictureId) => {
getPicture(pictureId).then(data => {
if (data.err) {
setValues({ ...values, err: data.err })
} else {
// populate the state
setValues({
...values,
name: data.name,
album: data.album._id,
formData: new FormData()
})
initAlbums()
}
})
}
const initAlbums = () => {
getAlbums().then(data => {
if (data.err) {
setValues({
...values,
error: data.err
});
} else {
setValues({
albums: data,
formData: new FormData()
});
}
});
}
const redirectUser = () => {
if (redirectToProfile) {
if (!error) {
return < Redirect to="/" />
}
}
}
useEffect(() => {
init(match.params.pictureId);
redirectUser(); // allows display the changes when a picture is updated
}, []);
...
}
And this is the warning that throws me:
React Hook useEffect has missing dependencies: 'init', 'match.params.pictureId', and 'redirectUser'. Either include them or remove the dependency array react-hooks/exhaustive-deps
I appreciate who can help me with this.