Skip to content

Instantly share code, notes, and snippets.

@HyunSeob
Created July 15, 2018 06:02
Show Gist options
  • Save HyunSeob/74368d6e6dc4c7f5ed36142675390dca to your computer and use it in GitHub Desktop.
Save HyunSeob/74368d6e6dc4c7f5ed36142675390dca to your computer and use it in GitHub Desktop.
import React, { Component } from 'react';
import { render } from 'react-dom';
type Omit<T, U extends keyof T> = Pick<T, Exclude<keyof T, U>>
interface ButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'onClick'> {
onClick: (value: ButtonHTMLAttributes<HTMLButtonElement>['value']) => void
}
class Button extends Component<ButtonProps> {
handleClick = () => {
this.props.onClick(this.props.value) // Okay now
}
render() {
return <button {...this.props} onClick={this.handleClick} />
}
}
render((
<Button
value="Hello"
onClick={() => console.log(value + ', world!')}
>
Button
</Button>
), document.getElementById('root'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment