Skip to content

Instantly share code, notes, and snippets.

@pushkar100
Created April 12, 2022 12:46
Show Gist options
  • Select an option

  • Save pushkar100/08c1b4299768706f7b2f6384050c7df5 to your computer and use it in GitHub Desktop.

Select an option

Save pushkar100/08c1b4299768706f7b2f6384050c7df5 to your computer and use it in GitHub Desktop.
const logClick = () => console.log("button clicked");
const callAll = (...fns) => (...args) => fns.forEach((fn) => fn(...args));
export const buttonPropsGetter = ({ customOnClick, ...props }) => ({
onClick: callAll(logClick, customOnClick), // Extensible
tabIndex: 0,
role: "button",
"aria-disabled": false,
text: "Button",
...props // The overrides
});
const Button = ({ text, buttonProps }) => {
return <button {...buttonProps}>{text}</button>;
};
// Usage:
<Button
{...buttonPropsGetter({
customOnClick: () => console.log("Sent email"),
text: "Send"
})}
/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment