When I was going through this example https://codesandbox.io/s/miniformik-v2-with-react-hooks-io0me it tells me that there is a missing dependencies and VS Code automatically inserts the dependencies (validate function). And it crashes the app because of it going into endless loop.
If I put the validate function inside the useEffect, it might work but the validate function is used elsewhere. How are you going about this? Do you refactor the whole code that it doesn't have this situation or just ignore the exhaustive deps warning?
Honestly, I would be fine with putting just state.values as deps but rules of hook, exhaustive deps keeps complaining.
React.useEffect(
() => {
if (validate) {
const errors = validate(state.values);
dispatch({ type: 'SET_ERRORS', payload: errors });
}
},
[state.values]
);
And I tried to solve it by calling validate inside useCallback but doesn't seem to work.
const callbackValidate = useCallback((values) => {
validate(values);
},
[]
);