You have different options for solving this problem.
1. Give up on component level action
This is the easiest approach. When input triggers a change, it triggers a delayed version of setSearch delays the server call.
import * as React from "react" import {connect} from "react-redux" import {setSearch} from "./actions" export default connect( null, function mapDispatchToProps(dispatch) { const setSearch_ = _.debounce(q => dispatch(setSearch(q)), 1000) return () => ({setSearch: setSearch_}) } )( function SearchForm(props) { const {setSearch} = props return ( <input type="search" onChange={setSearch} /> ) } )
2. Debounce with redux-saga
This approach requires more templates, but gives you much more control over your workflow. Using the saga, we intercept the SET_SEARCH action, cancel it, call the API, then submit a new action containing the results.
import {call, cancel, fork, put, take} from "redux-saga/effects" import {setSearchResults} from "./actions" import {api} from "./services" import {delay} from "./utils" export default function* searchSaga() { yield [
source share