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

107
Views
Encuentra el color del elemento de texto en React

Tengo un componente de enlace y quiero saber cuál es el color del texto. ¿Cómo haría eso en React?

Lo sé con Vanilla JS, puede encontrarlo con element.style.color sin embargo, si realizo algo similar con el siguiente código usando textEl.style.color , obtengo undefined .

 export function TextLink({ children, path, inline = false, dash = false }: TextLinkProps) { const textEl = useRef(""); return ( <StyledLink href={path} inline={inline} dash={dash} ref={textEl}> {children} </StyledLink> ); }
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Puede usar window.getComputedStyle() y pasar el elemento en sí mismo por su ref de la siguiente manera:

 const ref = React.useRef(); ... ... ... React.useEffect(() => { const style = window.getComputedStyle(ref.current) console.log(style.color); // rgb(255, 0, 0) }, []);

Ventana.getComputedStyle()

about 4 years ago · Juan Pablo Isaza Report

0

Estás olvidando el 'actual' con tu referencia. escríbelo así:

 textEl.current.style.color
about 4 years ago · Juan Pablo Isaza Report

0

Me da rgb(0, 0, 0)

 const textEl = React.useRef(null); React.useEffect(() => { if (textEl.current) { console.log(window.getComputedStyle(textEl.current).color) } }, [textEl])

O simplemente use textEl.current.style.color si no necesita uno calculado

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!