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

137
Vistas
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 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