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

246
Visualizações
Get child element width in parent component render - React

I have a project that uses basic React components that are compiled to vanilla JS and HTML with Babel. What I want to do is to be able to get the width of the buttons when they render (they can vary depending on the amount of text they have) and use the longest width value in the parent element so I can set both buttons to be that same width I want the CtaContainer to be responsible for setting the width of the button to be the same and aligning them accordingly. I can't set a fixed width as this will only happen when there is more than one button in the container

So first I have this index.js

const Index = () => {
return (
    <div>
        <h1 className={"hl-boldXL"}>Hey</h1>
        <p className={"copy-regularXL"}>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusantium animi aspernatur, beatae culpa eius esse in incidunt ipsa, iusto laborum optio placeat porro quam quo, suscipit veniam vero vitae! Dicta?</p>
        <CtaContainer>
            <CtaButton type={"primary"} url={"https://www.someurl.com"} text={"Primary"}/>
            <CtaButton type={"secondary"} url={"https://www.someurl.com"} text={"Secondary"}/>
        </CtaContainer>
    </div>
);};

Then I have a CtaButton component

const CtaButton = (props) => {

return (
    <a className={props.type} href={props.url} title={props.text}>{props.text}</a>
);};

And lastly I have the CtaContainer

const CtaContainer = ({children}) => {
const childRef = useRef(null)

useEffect(() => {
    if(children.length > 1) {
    }
});

return (
    <div>
        {children}
    </div>
);};
about 4 years ago · Juan Pablo Isaza
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