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

134
Views
Cómo condicional representar una clase en .map con react/typescript

He mapeado y filtrado a través de este objeto y quiero representar condicionalmente una clase basada en el texto que se genera. En este caso quiero que sea el texto "Ms". ¿Hay alguna forma de hacer esto dentro del objeto .mapped?

He intentado usar expresiones regulares. He intentado queryselecterAll. Lo he intentado para cada ciclo.

Siento que hay algo de lógica que me falta aquí.

Este es un objeto mapeado

 const [data, setData] = useState(false); const [searchUser, setSearchUser] = useState(""); useEffect(() => { setLoading(true); const fetchList = async (): Promise<UsersList> => { const result: any = await fetch("https://randomuser.me/api/?results=20") .then((res) => res.json()) .then((data) => { setData(data); setLoading(false); console.log(data); }); return result; }; fetchList(); }, []);

la clase

 .title { background-color: blue; }

objeto mapeado

 {data?.results .filter((val: any) => { if (searchUser === "") { return val; } else if ( val.name.first.toLowerCase().includes(searchUser.toLowerCase()) ) { return val; } else if ( val.email.toLowerCase().includes(searchUser.toLowerCase()) ) { return val; } else if ( val.location.city .toLowerCase() .includes(searchUser.toLowerCase()) ) { return val; } }) .map((d: any) => ( <div style={hoverStyle} className="text-blue-900 ease-in-out delay-150 hover:-translate-y-1 hover:scale-110 duration-300 border-white shadow-slate-500 bg-white hover:opacity-95 rounded-lg container p-5" > <img className="rounded-full w-44 h-44 " src={d.picture.large} /> <h2 className="">{d.name.title}</h2>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Puedes hacerlo en línea

 style={{background-color: d.name.title==='Ms' ? "blue" : "white" }}
about 4 years ago · Juan Pablo Isaza Report

0

objects.map((obj) => <div className={obj.name.title === 'Ms' ? 'classA' : 'classB'}>Ms</div>)
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!