How to handle this warning? (React Hook useMemo has missing dependencies: 'deleteTutorial' and 'openTutorial'. Either include them or remove the dependency array react-hooks/exhaustive-deps) If I put openTutorial and deleteTutorial inside useMemo hook, there wont be compile warning, but then I have a problem that those two functions wont work.
const openTutorial = (rowIndex) => {
const id = tutorialsRef.current[rowIndex].id;
props.history.push("/tutorials/" + id);
};
const deleteTutorial = (rowIndex) => {
const id = tutorialsRef.current[rowIndex].id;
TutorialDataService.remove(id).then((response) => {
props.history.push("/tutorials");
let newTutorials = [...tutorialsRef.current];
newTutorials.splice(rowIndex, 1);
setTutorials(newTutorials);
}).catch((e) => {
console.log(e);
});
};
const columns = useMemo(() => [
{
Header: "Naziv",
accessor: "title"
}, {
Header: "Opis",
accessor: "description"
}, {
Header: "Površina",
accessor: "povrsina"
}, {
Header: "Dužina x Širina",
accessor: properties => properties.duzina + ' x ' + properties.sirina
}, {
Header: "",
accessor: "actions",
Cell: (props) => {
const rowIdx = props.row.id;
return (<div>
<span onClick={() => openTutorial(rowIdx)}>
<i className="far fa-edit action mr-2"></i>
</span>
<span onClick={() => (confirmDialog('Da li želite obrisati parcelu?', () => deleteTutorial(rowIdx)))
}>
<i className="fas fa-trash action"></i>
</span>
</div>);
}
}
], []);
/EDIT/ Now I have problem that useCallback has missing dependency props.history. Is it ok to fix it like this:
const callHistory = useCallback(() => {
props.history.push("/tutorials");
}, [props.history]);
const deleteTutorial = useCallback((rowIndex) => {
const id = tutorialsRef.current[rowIndex].id;
TutorialDataService.remove(id).then((response) => {
callHistory();
let newTutorials = [...tutorialsRef.current];
newTutorials.splice(rowIndex, 1);
setTutorials(newTutorials);
}).catch((e) => {
console.log(e);
});
}, [callHistory]);