Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

188
Visualizações
React styles hover

I am building a React component library. Now, I want to add styles to the components. This works fine, but I want to change the background color if the mouse hovers. How can I do this?

import React from "react"

export interface IButtonProps {
  children: React.ReactNode;
  bg?: string;
  color?: string;
  style?: React.CSSProperties;
  onClick?: () => void;
}

export const Button: React.FC<IButtonProps> = props => {
  const {children, bg, color, style} = props;

  let _style: React.CSSProperties = style || {
    backgroundColor: "#12a4d9",
    color: "#fff",
    border: "none",
    padding: "10px 20px",
    borderRadius: "5px",
    cursor: "pointer",
    fontSize: "15px",
    fontWeight: 500,
    outline: "none",
    transition: "all 0.2s ease-in-out",
    boxShadow: "0px 2px 4px rgba(0, 0, 0, 0.1)",
  };

  if (bg) _style.backgroundColor = bg;
  if (color) _style.color = color;

  return (
    <button style={_style} {...props}>{children}</button>
  )
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I believe adding "&:hover": { //style here } inside your _style obj should work.

let _style: React.CSSProperties = style || {
  backgroundColor: "#12a4d9",
  color: "#fff",
  border: "none",
  padding: "10px 20px",
  borderRadius: "5px",
  cursor: "pointer",
  fontSize: "15px",
  fontWeight: 500,
  outline: "none",
  transition: "all 0.2s ease-in-out",
  boxShadow: "0px 2px 4px rgba(0, 0, 0, 0.1)",
  "&:hover": {
    backgroundColor: "#colorhex",
  }
};
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda