Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

121
Vistas
I can't get the data of the user by his id

I can't get the data from the API to display it on the screen when I try to retrieve it I get a 400 error I don't know how to retrieve the data I put the right routes and so far nothing works.

import Card from "../../components/Card";
import styled from "styled-components";
import { Loader } from "../../utils/styles/Atoms";
import { useFetch, useTheme } from "../../utils/hooks";
import freelancers from "../Freelances";

const CardsContainer = styled.div`
  display: grid;
  gap: 24px;
  grid-template-rows: 350px 350px;
  grid-template-columns: repeat(2, 1fr);
  align-items: center;
  justify-items: center;
`;

const LoaderWrapper = styled.div`
  display: flex;
  justify-content: center;
`;

export function getFreelance(id) {
  const freelance = [];
  console.log(freelance);
  return freelance.find((freelancer) => freelancer.id === id);
}

function Freelance() {
  const { theme } = useTheme();
  const freelanceData = getFreelance();
  const { data, isLoading, error } = useFetch(
    `http://localhost:8000/profile/?id=${freelanceData}`
  );
  console.log(data);
  const freelanceProfil = data?.freelanceProfil;

  if (error) {
    return <span>Oups il y a eu un problème</span>;
  }
  return (
    <div>
      {isLoading ? (
        <LoaderWrapper>
          <Loader theme={theme} data-testid="loader" />
        </LoaderWrapper>
      ) : (
        <CardsContainer>
          {getFreelance((profile, index) => (
            <Card
              key={`${profile.name}-${index}`}
              label={profile.job}
              title={profile.name}
              picture={profile.picture}
            />
          ))}
        </CardsContainer>
      )}
    </div>
  );
}

export default Freelance;

/*The different routes to make API calls*/

/*
     Node Js API

          ul 
          li /freelances
          li /profile/?id={id}
          li /survey
          li /results/?a1={answer1}&a2={answer2}&a3={answer3}...
  */
/*The model to get the unique user using his Id*/

const freelancesData = require("../models/freelances");

function getFreelance(id) {
  return freelancesData.find((freelancer) => freelancer.id === id);
}

module.exports = getFreelance;
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I think you need to use the ID instead of the whole object to call the API. I suggest do it like this:

const freelanceData = getFreelance();
const freelanceId = freelanceData.id; // get the ID from data
  const { data, isLoading, error } = useFetch(
    `http://localhost:8000/profile/?id=${freelanceId}`
  ); 
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda