can this be used together with redux-thunk (action creators)?
ronnaf opened this issue · comments
Ronna Firmo commented
Is something like this an ok thing to do?
export const getUsers = ({ query }, { signal }) => async (dispatch, getState) => {
const params = getUsersQuery(query)
const response = await fetch(`${client}/users${params}`, {
signal,
method: 'GET',
headers: {
authorization: `Bearer TOKEN_HERE`
}
})
const result = await response.json()
const users = result.docs
if (Array.isArray(users)) {
dispatch(receiveUsers({ users }))
} else {
throw new Error(users.message || 'Unable to get users!')
}
}