redux-saga designed to handle side effects such as receiving options for react-select asynchronously. This is why you should leave asynchronous stuff up to redux-saga . I never used react-select , but just by looking at the documentation I would solve it like this:
Your component is becoming very simple. Just get value and options from your redux store. optionsRequested - action creator for the OPTIONS_REQUESTED action:
const ConnectedSelect = ({ value, options, optionsRequested }) => ( <Select value={value} options={options} onInputChange={optionsRequested} /> ) export default connect(store => ({ value: selectors.getValue(store), options: selectors.getOptions(store), }), { optionsRequested: actions.optionsRequested, })(ConnectedSelect)
The saga definition for the OPTIONS_REQUESTED action that runs onInputChange loads the data with the specified searchTerm from the server and sends the OPTIONS_RECEIVED action to update the reduction store.
function* watchLoadOptions(searchTerm) { const options = yield call(api.getOptions, searchTerm) yield put(optionsReceived(options)) }
In other words: Make your Component as clean as possible and handle all side effects / asynchronous calls in redux-saga
I hope this answer was helpful to you.
source share