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

127
Views
¿Cómo uso el filtro dentro del filtro en reaccionar?

Tengo una matriz que se obtiene de los datos de una API, me gustaría filtrar categorías si está en categoría. Estaba intentando como :

 data.filter((post) => post.categories.filter((category) => if(category._id === category) return category

no funciono para mi

Aquí están los datos de mi matriz :

 export interface Post { categories: Category[] publishedAt: string _id: string _createdAt: string title: string author: { name: string image: string } comments: Comment[] description: string mainImage: { asset: { url: string } } slug: { current: string } body: [object] } export interface Category { _id: string _ref?: string title: string }

y probé esto también

 posts.map((post) => { post.categories.filter((category) => { if (category._ref === isCategory) return category; }); { return <Posts post={post} />; } });

Cómo puedo hacerlo ?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Supongo que quieres que las publicaciones tengan una category específica. Puede filtrar las publicaciones en función de si algunas de las categorías son iguales a la identificación de category definida.

Prueba así.

 {data .filter((post) => post.categories.some((cat) => cat._id === category)) .map((post) => ( <Posts post={post} /> ))}
about 4 years ago · Juan Pablo Isaza Report

0

Primero necesita obtener la lista de publicaciones que tienen en la categoría de matriz la categoría dedicada. Prueba esta solución

 const postsWithCategory = posts.filter((post) => post.categories.findIndex(cat => cat._ref === isCategory) !== -1); postsWithCategory.map(post => (<Posts post={post} />));

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!