Skip to content

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

@ronnaf

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions