Skip to content

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

Description

@ronnaf

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!')
  }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions