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

135
Visualizações
Get dimension of element using Refs

The problem that I'm stuck with some function that can get dimensions of some element. I'm working on project like Tabs and I want to 'border-bottom' the element that is active and make it nicely. So, I need to get width and left properties of each Tab. But Idk how to do it. Here is the my piece of code:

        const Tabs = ({renderTab, options, value}) => {   
        // option is the array that contains info about each Tab
        // value is a state  and need I to compare this value to change Tab etc
        
            const [sliderInfo, setSliderInfo] = useState({width: 0, left: 0});
        
            const currentTab = options.findIndex((tab) => tab.value === value );  
            
            const tabsRef = options.map(() => {
                return useRef(null);
            });
            
            useEffect(() => {
                // I tried to something like that, but it didnt work
                setSliderWidth({
                    width: tabsRef.current.getBoundingClientRect().width ,
                    left: tabsRef.current.getBoundingClientRect().left
                });
        
            }, [tabsRef]);
    
            return (
    
                <StyledTabsContainer>
                 {options.map((tab, i) => {  
                    return (
                        <div key={i}  className='wrapper'  ref={tabsRef[i]}  value={value} >
                            { renderTab(tab) }
                           
                        </div>            
                    )
                 })
                 }
                 <TabSlider width={sliderInfo.width} left={sliderInfo.left}></TabSlider>  
                
                </StyledTabsContainer>
        )
}

I will be very grateful if you can help me somehow!)

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