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

152
Views
TypeError no capturado: no se pueden leer las propiedades de nulo (leyendo '_id')

Estoy creando un sitio web de redes sociales de un youtuber y tengo un problema en la parte de frontend (React). Mi error es: no se pueden leer las propiedades de nulo (leyendo '_id'). Lo he comprobado muchas veces comentando cada parte y el problema está en la publicación. Ayuda.

 const Account = () => { const dispatch = useDispatch(); const { loading, error, posts } = useSelector((state) => state.myPosts); const { error: likeError, message } = useSelector((state) => state.like); useEffect(() => { dispatch(getMyPosts()); }, [dispatch]); useEffect(() => { if (error) { alert.error(error); dispatch({ type: "clearErrors" }); } if (likeError) { alert.error(likeError); dispatch({ type: "clearErrors" }); } if (message) { alert.success(message); dispatch({ type: "clearMessage" }); } }, [alert, error, message, likeError, dispatch]); return loading ? ( <Loader /> ) : ( <div className="account"> <div className="accountleft"> {posts && posts.length > 0 ? posts.map((post) => ( <Post key={post._id} postId={post._id} caption={post.caption} postImage={post.image.url} likes={post.likes} comments={post.comments} ownerImage={post.owner.avatar.url} ownerName={post.owner.name} ownerId={post.owner._id} isAccount={true} isDelete={true} /> )) : ( <Typography variant="h6">You have not made any post</Typography> )} </div> <div className="accountright"></div> </div> ); }; export default Account;
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Esto parece ser un problema con el objeto de publicación que está recorriendo actualmente como nulo. Debe verificar que el valor sea nulo dentro de su bucle.

 { posts && posts.length > 0 ? ( posts.map((post) => post ? ( <Post key={post._id} postId={post._id} caption={post.caption} postImage={post.image.url} likes={post.likes} comments={post.comments} ownerImage={post.owner.avatar.url} ownerName={post.owner.name} ownerId={post.owner._id} isAccount={true} isDelete={true} /> ) : null ) ) : ( <Typography variant="h6">You have not made any post</Typography> ); }

editar: a diferencia de lo que otros parecen estar diciendo, esto no es un problema con la propiedad _id o el ciclo de publicaciones, ya que esto no crearía el mismo error. Está intentando leer la propiedad _id de la post y encuentra que post es nula, no la propiedad _id .

about 4 years ago · Santiago Trujillo 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!