Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

109
Vistas
Find Color of Text Element in React

I have a Link component and I want to find out what the color of the text is. How would I do that in React?

I know with Vanilla JS, you can find it with element.style.color however if I perform similar with below code using textEl.style.color I get 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 Respuestas
Responde la pregunta

0

You can use window.getComputedStyle() and pass the element itself by its ref like so:


const ref = React.useRef();
...
...
...

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

Window.getComputedStyle()

about 4 years ago · Juan Pablo Isaza Denunciar

0

You are forgetting the 'current' with your reference. write it like this :

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

0

Gives rgb(0, 0, 0) to me

const textEl = React.useRef(null);

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

Or simply just use textEl.current.style.color if you don't need computed one

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda