Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

131
Visualizações
How to make a resource with a map and generate an array of objects

I am a beginner in JavaScript technology, I have a question about how to go through an object resulting from a GET. This my code

import { useRouter } from 'next/router'
import useSWR from 'swr'

import { api } from '../lib/api'

export const getProfiles = () => {
  const { query, isReady } = useRouter()
  const {
    data: response,
    error,
    mutate
  } = useSWR(
    isReady
      ? `/profile/?search=${query.search}&order=${query.order}&page=${query.pageNumber}`
      : null,
    api
  )

  const profiles = response?.data?.map(profile => {
    return {
      ...profile,
      label: ProfilesLabelEnum[profile.name]
    }
  })

  return {
    profiles,
    isLoading: !error && !response?.data,
    isError: !!error,

    mutate
  }
}

export enum ProfilesLabelEnum {
  SUP = 'Supervisor',
  WOR = 'Servidor',
  MOD = 'Moderador',
  ADM = 'Administrador'
}

I need to fill a Select ("react-select") with this data the structure that the Select needs in its options property is something like this

const options = [
  { value: "1", label: "Administrador" },
  { value: "2", label: "Colaborador" },
  { value: "3", label: "Supervidor" }
];

but as I told you I don't know how to go through GET object to get this back, I was using a traditional HTML <select> before and I filled it in the following way in

<select
    required
    {...register('perfil')}
    id="perfil"
    name="perfil"
    placeholder={
      isAddMode ? 'Selecione um Perfil' : row.profile.name
    }
    size="md"
    variant="outline"
 
  >
    {profiles?.map(items => (
      <option key={items?.id} value={items?.id}>
        {items?.label}
      </option>
    ))}
  </select>

now to the react-select I must pass an object in the options property as follows

 <Select
          id="color"
          options={options}
          onChange={this.handleChange}
          onBlur={this.handleBlur}
          value={this.props.value}
        />
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda