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

214
Views
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 answers
Answer question

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 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!