Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

129
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!