Skip to content

Cant seem to get Throttle working with onClick #47

@alex-r89

Description

@alex-r89

Hi there,

Apologies, this may be down to me implementing the package incorrectly, but I dont seem to be able to get throttle to work with an onClick - if I rapidly click the button, the console log is fired multiple times. I have this set up as follows:

//throttled-button.js
const ThrottledButton = (props) => {
  const handleOnClick = () => throttle(1000, true, props.onClick)

  return <button onClick={handleOnClick} {...props}>{props.children}</button>
}


// logout.js
const handleLogout = () => {
  console.log("FIRED")
  logoutUser()
}

 <ThrottledButton onClick={handleLogout} type='button'>Logout</ThrottledButton>

I have also tried this in the following configuration, which also doesnt seem to work:

// logout.js
  const handleLogout = throttle(1000, true, () => {
    console.log("FIRED")
    logoutUser()
  })

 <button onClick={handleLogout} type='button'>Logout</button>

As mentioned, if I rapidly click the buttons in either of these configurations, I see FIRED console logged multiple times.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions