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

216
Vistas
React Use param in function outside of event

I'm trying to take a function out of an onClick event but i don't know why it's not working.

This code works

<ul className="list-group mt-3">
    {news.map((item) => (
        <li 
            key={item.name} 
            className="list-group-item text-capitalize"
        > 
            {item.name}
            <button 
                className="btn btn-dark btn-sm float-right"
                onClick={ () => dispatch( newsAction(item.url) ) }
            >
                Info
            </button>
        </li>
    ))}
</ul>

But i'm trying to cleanUp the code using this

const handleGetInfo = (url) => {
    dispatch( newsAction(url) )
}

return (
    <ul className="list-group mt-3">
        {news.map((item) => (
            <li 
                key={item.name} 
                className="list-group-item text-capitalize"
            > 
                {item.name}
                <button 
                    className="btn btn-dark btn-sm float-right"
                    onClick={ handleGetInfo }
                >
                    Info
                </button>
            </li>
        ))}
    </ul>
)

And it throws a 404 error when calling the API

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

const handleGetInfo = (url) => () => {
    dispatch( newsAction(url) )
}

return (
    <ul className="list-group mt-3">
        {news.map((item) => (
            <li 
                key={item.name} 
                className="list-group-item text-capitalize"
            > 
                {item.name}
                <button 
                    className="btn btn-dark btn-sm float-right"
                    onClick={ handleGetInfo(item.url) }
                >
                    Info
                </button>
            </li>
        ))}
    </ul>
)
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