Reputation: 73888
I am developing a map application. It consists of two components:
These components rely on the following state domains:
state.userAddress = {
name: 'Didzioji g. 10, Vilnius'
};
state.addressSearch = {
state: 'inactive',
query: '',
addresses: []
};
When user selects an address from address suggestion list it invokes an event handler onSelectAddress
. onSelectAddress
needs to trigger two state changes:
userLocation
to new location; andWhat is the correct way to design this?
USER_LOCATION_CHANGE
change and another to invoke ADDRESS_SEARCH_HIDE
; orUSER_CHANGE_LOCATION
) which is handled by two different reducers?Upvotes: 3
Views: 247
Reputation: 377
In similar situation I choose to dispatch another action from target action.
Trying to show this in code
module.exports.locationChange = function clickElement(element) {
return function(dispatch, getState) {
dispatch({
type: actionTypes.USER_CHANGE_LOCATION
});
dispatch({
type: actionTypes.ADDRESS_SEARCH_HIDE
});
}};
I use redux-thunk for async action.
Upvotes: 3