Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

134
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!