I'm fairly new to Typescript and React. I've been trying to implement the react-rewards npm library and I have solved all except one issue.
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>
)
}
}
After running npm start I get an error which says TypeError: this.reward is undefined. What is the best way to resolve?