Using React-Redux-Thunk... I am trying to understand the best way to handle this use case in my reducer. On inserting a new searchterm in the database, I need to update my state ( which is a json summary of top searches ( key"value- searchterm:count). My objective is to add 1 to the count if my serachterm key exists else create a new key:value with "serachterm":1
How do i code this in my reducer
export default function topSearchReducer(state = {topSearches: []}, action) {
console.log('action', action);
console.log('Inside Top Search reducer state', state);
switch (action.type) {
case 'FETCH_TOP_SEARCHES':
return {topSearches: action.payload}
case 'UPDATE_TOP_SEARCH'
if(action.searchterm in state.topSearches[0]){
console.log( 'FOUND IN OBJECT!');
}
default:
return state
}
};