'Redux dispatch is a little slow
//Reducer file
const options = {
name: 'searchResult',
initialState: [],
reducers: {
setSearchResult(state, action) {
return action.payload
}
}
}
export const searchResultSlice = createSlice(options)
//Component file
const handleClick = (dispatch) => {
//Problem lies here
dispatch({
type: 'searchResult/setSearchResult',
payload: []
})
}
I have a searchbar and using an API to get data relating to search term. Now, the problem is suppose, a search is done and the response of API gets stored in redux store searchResult. After that, I want the array to be empty on click of a close button. So, I empty the array by dispatching the action with an empty array but it takes a second or two to empty the array. Why is it so?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
