Skip to content

Instantly share code, notes, and snippets.

@jsmanifest
Created March 13, 2020 05:52
Show Gist options
  • Save jsmanifest/d9d8ea585e21c4df812c5d670f65590c to your computer and use it in GitHub Desktop.
Save jsmanifest/d9d8ea585e21c4df812c5d670f65590c to your computer and use it in GitHub Desktop.
import React from 'react'
function MyButton({ children, onClick: onClickProp, ...rest }) {
return (
<button
onClick={(e) => {
window.alert(e.currentTarget.name)
if (onClickProp) {
onClickProp(e)
}
}}
{...rest}
>
{children}
</button>
)
}
function App() {
function onClick(e) {
console.log('Here is the event object', e)
}
return (
<div>
<MyButton name="alerter" onClick={onClick}>
Alert
</MyButton>
</div>
)
}
export default App
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment