My useEffect hook is running when dependency has not changed.
useEffect(() => {
console.log('Search useEffect Run')
dispatch(fetchSearchData(searchItem));
}, [dispatch, searchItem]);
searchItem is part of a Redux slice as:
const searchItem = useSelector((state) => state.posts.searchTerm);
const initialState = { posts: [], searchTerm: '', selectedSubreddit: 'r/pics/', };
The useEffect is running when searchItem is not changing from empty string.
Thanks for any help.
I have tried useCallback but getting the same issue.
This is inside a function and useEffect runs twice each time function is rendered (for a unrelated event).
Cheers