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
React Activate the button with one click

There are four buttons. You can currently move the link with one click. However, you need to double-click the button to activate the color of the button.

I want to activate the link and button with a click. Would it be possible to get some help?

Sidebar.js

const [selectBtn, setSelectBtn] = useState();

{SETTING_BAR_ICON.map(data => {
       return (
        <SidebarIcon
         key={data.id}
         src={data.img}
         select={data.select}
         link={data.link}
         handleChangeBtnColor={() => 
         setSelectBtn(data.id)}
         isSelectBtn={selectBtn === data.id}
         />
        );
       })}

SidebarIcon.js

<SidebarIconContainer>
      {isSelectBtn ? (
        <ImgBackground>
          <ImgSelect src={select} />
          <ImgText>{link}</ImgText>
        </ImgBackground>
      ) : (
        <Link to={`/${link}`}>
          <ImgFormat src={src} onClick=. 
          {handleChangeBtnColor} />
        </Link>
      )}
</SidebarIconContainer>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

First issue you never close the function curly bracket in the handleChangeBtnColor property of the SidebarIcon. You need a } before the />. You also need the two methods inside to be wrapped in curly brackets. When you use arrow functions use curly brackets all the time, lie this:

const doSomething = () => {
  ...
}

Unless you only have one thing to return inside then you can leave out the curly bracket like this:

// shorthand
const doSomething = () => doAThing()
const getSomething = () => 'thing'

// same as this
const doSomething = () => {
  return doAThing()
}
const getSomething = () => {
  return 'thing'
}

// if you go to the next line you should use parenthesis
const doSomething = () => (
  doAThing()
)

But I don't think that will fix it. Rather than use a Link tag, use the useNavigation hook and change the path in the handleChange... function. So something like this:

import { useNavigate } from 'react-router-dom'

const navigate = useNavigate()

return (
  <SidebarIcon
    ...
    handleChangeBtnColor={(link) => {
      setSelectBtn(data.id)
      isSelectBtn={selectBtn === data.id}
      navigate(`/${link}`)
    }}
  />
)
<DivStyledLikeYourOtherLinks onClick={() => handleChangeBtnColor(link)} />
about 4 years ago · Juan Pablo Isaza Denunciar
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