Still getting used to this.
I have checked out questions here and here and I still feel uncomfortable about how to go about this. These are not clear from my perspective.
Basically I have clicked on the "Login" button and have requested a JWT login token and succesfully received it. What I have noticed is that I can at this point download those rarely changed lists like states or suburbs/postcodes which are large (the latter) and should be at the spa's immediate use rather than tacking it onto a call for a client.
I want to, upon successfully receiving the token immediately do an API call for those lists and store them in local storage. There is no "event" it should fire straight after a successful retreival of a JWT...
Here is the action for retreiving a JWT in react:
export const requestLoginToken = (username, password) => (dispatch, getState) => { dispatch({type: REQUEST_LOGIN_TOKEN, payload: username}) const payload = { userName: username, password: password, } const task = fetch('/api/jwt', { method: 'POST', body: JSON.stringify(payload), headers: { 'Content-Type': 'application/json;charset=UTF-8' }, }) .then(handleErrors) .then(response => response.json()) .then(data => { dispatch({type: RECEIVE_LOGIN_TOKEN, payload: data}) saveJwt(data) }) .catch(error => { clearJwt() dispatch({type: ERROR_LOGIN_TOKEN, payload: error.message}) }) addTask(task) return task } I beleive the place for adding a second API call would be after "saveJwt()" but how.
Do/can I send it off to another export const action/function in another part of the application?
If I write something similar to this and by putting the name of the function in with a parameter of "JWT" eg
.then(retrieveSelectData) that it will go off to that separate folder with that export function and execute an API call at the same time applying a dispatch...and then return..
Could some one outline if this is a correct and reasonable way of making two API calls as one. I still have to get the JWT (and use it in the second) so I cant do the second call without the first.
redux-thunk?