Last active
June 24, 2016 09:09
-
-
Save ryanflorence/d18ada55ef8d7c4929bb to your computer and use it in GitHub Desktop.
This file contains 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
// make a "base" component | |
const FakeButton = (props) => ( | |
<div | |
{...props} | |
style={{ | |
cursor: 'default', | |
border: '1px solid', | |
borderRadius: '3px', | |
...props.style | |
}} | |
tabIndex="0" | |
role="button" | |
onKeyDown={(e) => e.key === 'Enter' && props.onClick(e)} | |
onKeyUp={(e) => e.key === 'Space' && props.onClick(e)} | |
onClick={props.onClick} | |
/> | |
) | |
FakeButton.defaultProps = { | |
onClick() {} | |
} | |
// wrap it to add specific behavior | |
const AlertButton = (props) => ( | |
<FakeButton | |
{...props} | |
onClick={(event) => alert(props.message)} | |
/> | |
) | |
// use it anywhere | |
render(<AlertButton message="hello"/>, el); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks great. Is there some kind of transformation I am missing ? How is React.createElement() taking the return of another createElement() as first argument ? Adding this to jsfiddle does throw this error as expected.
Uncaught TypeError: Can't add property context, object is not extensible
what am i missing ?