I need to call this logEvent function inside useEffect hook only when the searchTerms string is changed. The problem is that total_result is equal to the previous state of value. So I need somehow get the actual latest value of data?.hits.total.value. Is it possible to do it without making useEffect like this:
useEffect(() => { if (searchTerms) { analyticsService?.logEvent(ANALYTICS_EVENTS.SEARCH_COMPLETED, { total_results: data?.hits.total.value, error_message: null, }); } }, [searchTerms, data?.hits.total.value]);
Because in some cases the total_results can be the same, so it will not call my logEvent function.
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)