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

144
Views
No se puede desestructurar la propiedad 'imagen' de 'profileData' ya que no está definida

Estaba tratando de desestructurar mi variable ProfileData que contiene un objeto. Pero tengo un problema para mostrar los datos de la API, así que cuando pasa, mi página se rompe y me envía este error "No se puede desestructurar la propiedad 'imagen' de 'profileData' porque no está definida". No sé el motivo. del mensaje de error es la ausencia de la clave "last_paper" en algunos objetos pero no se como evitar este problema. No sé dónde está el problema y no sé cómo evitar este problema.

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

0

Parece que freelaneData no está presente en todas las respuestas.

Normalice la respuesta de su base de datos para incluir un objeto vacío de todos modos, o recurra a un objeto vacío como:

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

0

Si no desea que su sitio se bloquee cuando profileData no está definido . Simplemente siga el siguiente código:

 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 || {};

En este caso, la imagen, el nombre u otras propiedades que estamos tratando de desestructurar no estarán definidas .

about 4 years ago · Juan Pablo Isaza Report

0

Acabo de solucionar el problema. Había escrito mal freelaneData en lugar de freelanceData. Gracias por tu ayuda.

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