Is it right to make requests in the action creators?

Is it right to make requests in the action creators?

For example, there is a file actions.js

There are as the usual action-cretary, a La
export const addUserAC= (value) => (
{
 type: ADD_USER,
 payload: value
}
);


and functional:
export const addUser= () => {
 return (dispatch) => {
 axios.get(`${server_base}/api/addUser`, {
 params: {
 id: store.getState().user.id
}
})
 .then(function (response) {
dispatch(addUserAC(response.data));
})
 .catch(function (error) {
console.log(error);
});
};
};


Is it right? Possible to do so?
April 7th 20 at 15:30
2 answers
April 7th 20 at 15:32
Solution
It is possible and necessary, then they can be here to importnat in any component and to reuse.
April 7th 20 at 15:34
Solution
The way you described is acceptable.

I can still recommend:
1) Make the entire query logic in Saga, then all action creature will be pure functions, which is very convenient.
2) Make connections in mallary, which clearly reduces the number boilerplate and standartisied the treatment of IPA.

Find more questions by tags ReactRedux