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

197
Views
Componente de pestaña: los botones de pestaña desplazables horizontalmente se vuelven a renderizar al hacer clic

Detalles del componente: este es un componente de pestaña donde los botones de pestaña se pueden desplazar horizontalmente

Problema: cuando me desplazo horizontalmente y hago clic en un botón de pestaña. El desplazamiento horizontal se restablece. Tal vez todo el contenedor de pestañas se vuelve a representar debido al IDK de setState.

Esperando: quiero poder hacer clic en un botón de pestaña y no actualizar la posición de desplazamiento horizontal del contenedor del botón.

Código actual:

 function Tabs(props) { const [tabState, setTabState] = useState(0); const [menuData, setMenuData] = useState('') const TabContainer = styled.div` width: 100%; display: flex; flex-wrap: no-wrap; flex-direction: row; margin: 0 0 20px 0; padding: 20px; align-items: flex-start; justify-content: flex-start; background-color: #fff; overflow-x: auto; const handleTabClick = (index) => { setTabState(index);}return( <> <TabParent> <TabContainer> {props.data && props.data.dataDeets.map((dataDeets,catIndex) => { return ( <TabBtn key={catIndex} onClick={() => handleTabClick(catIndex) } active={tabState === catIndex ? true : false}> {menu.category} </TabBtn> ) }) } </TabContainer> </TabParent> {props.data && props.data.menu.map((menu, catIndex) => { return ( <TabCont key={catIndex} active={tabState === catIndex ? true : false}> <small> {data.categoryDesc} </small> {data.items.map((items, itemIndex) => { return ( <div key={itemIndex} onClick={event => props.openDetails(catIndex, itemIndex, event)}> <ItemCard key={itemIndex} title={items.title} imgurl={items.imgurl} desc={items.desc} price={items.price} /> </div> ) }) } </TabCont> ) }) } </> );
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Mi error de novato: espero que esto ayude a otros novatos :)

useState hizo que todo el componente se volviera a renderizar

Mi solución Mover la salida como un componente separado. Esto permite Para mantener su propio estado.

about 4 years ago · Juan Pablo Isaza Report
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!