My function makes 10 async calls to the backend when the filterState has been changed. I want it to be called once per change.
useEffect(() => {
const getQuery = async () => {
let query = filterActions.getQueryString()
taskService.get(query).then(res => {
console.log('tasks res', res)
setQueriedTasks(res)
})
}
getQuery()
}, [filterState])
How I update the filter
const updateFilter = (updates) => {
dispatch({type: 'SET_FILTER', payload: updates})
}
My reducer to update state
function reducer(state, action) {
switch (action.type) {
case 'SET_FILTER':
return Object.assign({...state}, action.payload)
}
}