Skip to content

Instantly share code, notes, and snippets.

@alanbsmith
Created December 14, 2021 02:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alanbsmith/eabea04a56dd39fd7bce2ae6167c18bd to your computer and use it in GitHub Desktop.
Save alanbsmith/eabea04a56dd39fd7bce2ae6167c18bd to your computer and use it in GitHub Desktop.
function iterator
function eventHandler(...fns) {
  return (e) => {
    fns.forEach(fn => fn(e);
  }
}

function Component({ onClick )) {
  const handler = useClickable();
  
  return <div onClick={eventHandler(handler, onClick)} />
}

// Or you could do this:
function eventHandler(event, ...fns) {
  fns.forEach(fn => fn(event);
}

function Component({ onClick )) {
  const handler = useClickable();
  
  return <div onClick={event => eventHandler(event, handler, onClick)} />
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment