我需要帮助制作一个可重用的组件
下面是调用组件的代码:
export var MyPublicFunction = function (inArg: number) {
alert(inArg);
}
ReactDOM.render(<MyButton name="My Button" clickFunction={MyPublicFunction(1)} >Button</MyButton>, document.getElementById('content'));
这里是我要写的部分:
interface myProps {
name: string;
clickFunction: any
}
class MyButton extends React.Component<myProps, {}> {
constructor(props: myProps) {
super(props);
}
render() {
return (<div>
<button ref="btn1" onClick={this.props.clickFunction} >
{this.props.name}
</button>
</div>);
} //end render.
} //end class.