I have such a situation, I need to execute my function each time the string searchTerms and total.value is changing. Here is how it looks like
useEffect(() => {
if (searchTerms) {
analyticsService?.logEvent(ANALYTICS_EVENTS.SEARCH_COMPLETED, {
total_results: data?.hits.total.value,
error_message: null,
});
}
}, [data?.hits.total.value && searchTerms]);
But it works not as expected, I need to execute this function only when data.hits.total.value && searchTerms is changed. Not OR!
If I will make it like this
[data?.hits.total.value, searchTerms]
Then my function would log 2 times each search, but I don't need it.
How can I fix it?