Dashboard component:
const [breadcrumbs, setBreadcrumbs] = useState<Crumb[]>([]);
const handleCrumbs = (data: Crumb[]) => {
setBreadcrumbs(data);
};
return (
<>
<Breadcrumbs crumbsArray={breadcrumbs} />
<Route
path={`${path}/partners`}
render={() => <Partners crumbs={handleCrumbs} />}
/>
</>
);
Partners component:
const Partners: React.FC<any> = ({ crumbs }) => {
useEffect(() => {
const arr = [1, 2, 3, 4, 5];
crumbs(arr);
}, []);
}
There i'm getting an error:
React Hook useEffect has a missing dependency: 'crumbs'. Either include it or remove the dependency array. If 'crumbs' changes too often, find the parent component that defines it and wrap that definition in useCallback react-hooks/exhaustive-deps
How can i refactor this with useCallback? I can just disable eslint error and everything would work as expected, but how to do that in a "right way"?
Logic behind this, is when Partners component is mounted, i'm setting breadcrumb items in the parent component - Dashboard.
UPDATE 1
Dashboard:
const handleCrumbs = useCallback((data: Crumb[]) => {
setBreadcrumbs(data);
}, []);
Partners:
const Partners: React.FC<any> = ({ crumbs }) => {
useEffect(() => {
const arr = [1, 2, 3, 4, 5];
crumbs(arr);
});
}