Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can this be used together with redux-thunk (action creators)? #296

Open
ronnaf opened this issue Jul 18, 2020 · 0 comments
Open

can this be used together with redux-thunk (action creators)? #296

ronnaf opened this issue Jul 18, 2020 · 0 comments

Comments

@ronnaf
Copy link

ronnaf commented Jul 18, 2020

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!')
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant