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

145
Vistas
Cannot destructure property 'picture' of 'profileData' as it is undefined

I was trying to destructure my ProfileData variable that holds an object. But, I have a problem to display the API data, so when it passes, my page breaks and sends me this error "Cannot destructure property 'picture' of 'profileData' as it is undefined.".I don't know the reason of the error message is the absence of the key "last_paper" in some objects but I don't know how to avoid this problem. I don't know where the problem is and I don't know how to avoid this problem.

function Profile() {
   const { id: queryId } = useParams();
   const [profileData, setProfileData] = useState({});
   useEffect(() => {
      fetch(`http://localhost:8000/freelance?id=${queryId}`)
         .then((response) => response.json())
         .then((jsonResponse) => {
            setProfileData(jsonResponse?.freelaneData);
         });
   }, [queryId]);

   const { picture, name, location, tjm, job, skills, available, id } = profileData;
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

It looks like freelaneData is not present in all responses.

Either normalise your database response to include an empty object anyhow, or fallback to an empty object like:

setProfileData(jsonResponse?.freelaneData || {});
about 4 years ago · Juan Pablo Isaza Denunciar

0

If you don't want your site to crash when profileData is undefined . Just follow the below code :

function Profile() {
   const { id: queryId } = useParams();
   const [profileData, setProfileData] = useState({});
   useEffect(() => {
      fetch(`http://localhost:8000/freelance?id=${queryId}`)
         .then((response) => response.json())
         .then((jsonResponse) => {
            setProfileData(jsonResponse?.freelaneData);
         });
   }, [queryId]);

   const { picture, name, location, tjm, job, skills, available, id } = profileData || {};

In this case , picture , name or other properties which we are trying to de structure will be undefined .

about 4 years ago · Juan Pablo Isaza Denunciar

0

I just fixed the problem I had misspelled freelaneData instead of freelanceData. Thank you for your help.

function Profile() {
   const { id: queryId } = useParams();
   const [profileData, setProfileData] = useState({});
   useEffect(() => {
      fetch(`http://localhost:8000/freelance?id=${queryId}`)
         .then((response) => response.json())
         .then((jsonResponse) => {
            setProfileData(jsonResponse?.freelanceData);
         });
   }, [queryId]);

   const { picture, name, location, tjm, job, skills, available, id } =
      profileData;
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