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

183
Views
¿Cómo puedo cambiar el color de un elemento seleccionado en un mapa de reacción con la función onClick?

Estoy tratando de comparar el clic actual con hasClip en un mapa de reacción dado y vaciar el color si el resultado es idéntico al id y la categoría, mientras que si no es el mismo, relleno el color.

¿Puede alguien por favor ayudarme a averiguar cómo puedo resolver esto?

A continuación, tengo una matriz donde mapeo el tipo de clave de categoría y la identificación del elemento:

 const data = [ { keyType: "category", filtered: [ { _id: 1, name: "Stocks", paramValue: "stocks" }, { _id: 19, name: "Commodities", paramValue: "commodities" }, ], }, { keyType: "topics", filtered: [ { _id: 8, name: "Preferred stocks", paramValue: "preferred-stocks" }, { _id: 24, name: "Stocks", paramValue: "stocks" }, ], }, ]; const hasClip = [ { _id: 1, keyType: "category", name: "Stocks", paramValue: "stocks" }, { _id: 8, keyType: "topics", name: "Preferred stocks", paramValue: "preferred-stocks", }, ]; const handleFill = (hasClip, category, id) => { checkKeyword(hasClip, category, id); }; const checkKeyword = (hasClip, category, id) => { const result = hasClip.some( (item) => item._id === id && item.keyType === category ); return result; }; const par = () => { return ( <> {data.map((category) => ( <> <h1 key={category.keyType}>{category.keyType}</h1> {category.filtered.map((item) => ( <styledComp key={item._id} onClick={() => { handleFill(hasClip, category.keyType, item._id); }} $clip={checkKeyword(hasClip, category.keyType, item._id)} > {item.name} </styledComp> ))} </> ))} </> ); }; export default par; const styledComp = styled.div` width: 50px; height: 50px; background-color: ${({ $clip }) => ($clip ? "red" : "none")}; `;
about 4 years ago · Santiago Gelvez
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!