我對Typescript和React很新。我一直在嘗試實(shí)現(xiàn)react-rewardsnpm庫,除了一個問題我已解決了所有問題。type Props = {}class Surprisebutton extends Component<Props>{
reward: any;
render() {
return (
<Reward
ref={(ref) => { this.reward = ref }}
type='memphis'>
<Button onClick={this.reward.rewardMe()} style={styles.button} variant="contained" color="primary">
Surprise!
<FavoriteIcon style={{ marginLeft: 10 }} />
</Button>
</Reward>
)
}}跑完后npm start我得到一個錯誤TypeError: this.reward is undefined。什么是最好的解決方法?
Typescript:TypeError未定義
皈依舞
2019-04-18 10:15:40