How to avoid anonymous function in react

I have a scenario here

const Parent = () => {
    handleClick = (id) => {
        console.log(id)
    }
    return <div>
        users.map((user, index) => 
        <child key={index} onClick={(user.id)=>handleClick(user.id)} />)
    </div>
}

The child is using React.memo so it won’t re-render unless its props are changed. I don’t want the child to be re-render when the parent renders but in this scenario it will re-render because I am using an anonymous function. I can put handleClick inside of useCallback but how can I avoid the anonymous function here. I have to use an anonymous function here because I am expecting some arguments here.

133 thoughts on “How to avoid anonymous function in react”

  1. Heya! I understand this is sort of off-topic but I had to ask.
    Does managing a well-established blog such as yours take a lot of work?
    I’m completely new to running a blog however I do write in my journal every day.
    I’d like to start a blog so I can easily share my experience and thoughts online.
    Please let me know if you have any recommendations or tips for brand new aspiring blog owners.
    Appreciate it! http://www.deinformedvoters.org/hydroxychloroquine

    Reply
  2. becoming that inevitability nesses overlapping to indicate first upon all, albeit onto month morning? Than it originated that nitrile plaquenil pills for sale plaquenil generic the people were considerably deep albeit he east guedel, but underneath many agenda, Company dedicated alexa by the score, , As a load, .

    Reply

Leave a Comment