1. import axios from 'axios';
2. import {normalize} from 'normalizr';
3. import actionTypes from '../../../config/action-types';
4. import settings from '../../../config/settings';
5. import {setNormalized} from '../../../utils/general';
6. import {USER} from '../../../utils/normalize';
7. import {tokenHeader} from '../../../utils/requestHeaders';
8. export const editProfile = data => **async dispatch =**> {
9. let formData = new FormData();
10. if(data.image) formData.append('image', data.image);
11. try {
12. const response = await axios.patch(`${settings.API_ROOT}/profiles/${data.id}`, formData, tokenHeader());
13. localStorage.setItem('activeUser', JSON.stringify(response.data));
14. dispatch({
15. type: actionTypes[`LOGIN_SUCCESS`],
16. payload: response.data
17. });
18. const {entities} = normalize(response.data, USER);
19. setNormalized(dispatch, entities);
20. return entities;
21. } catch(error) {
22. throw error;
23. }
24. };
What line number 10 does exactly i can’t find any solution to this.
Full project is https://github.com/buckyroberts/Vataxia-Frontend opensource.
Using this answer the function should do async call lke python language does but
dispatch
is from redux module
async () => {
// do something
}