Q:

Avoid useEffect to be triggered when one nested dependency changes

My form has 3 fields, lambda, period and filterPattern. When the values of lambda and period change, it will trigger handleSearch. However, I don't want handleSearch to be triggered when filterPattern changes.
If I don't put filterPattern in the dependency array, then handleSearch cannot get the latest value of filterPattern.
How to avoid useEffect to be triggered when one nested dependency changes? Thanks.
const getLogQuery = useCallback(() => ({
  lambda,
  period,
  filterPattern,
}), [lambda, period, filterPattern]);

const handleSearch = useCallback(async () => {
  await getLambdaLogs(getLogQuery());
}, [getLogQuery]);

useEffect(() => {
  handleSearch();
}, [handleSearch]);

const getLambdaLogs = async (query) => {
  const logs = await LambdaService.getLambdaLogs(query);
  setLogItems(logs);
}

A:

I'm making a few assumptions, but the second argument of useEffect are its dependencies, the things it watches to know when to fire.  So instead of
useEffect(() => {
  handleSearch();
}, [handleSearch]);

Which doesn't make any sense, to watch a function and then call that function if it changes, change that to
useEffect(() => {
  handleSearch();
}, [lamba, period]);
```

