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

114
Views
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 answers
Answer question

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 Report
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!