Created
April 12, 2022 12:46
-
-
Save pushkar100/08c1b4299768706f7b2f6384050c7df5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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