I have a class that looks something like this
export class TestScreen extends Component<any, LoginScreenState> {
private wallet: Wallet;
async connect() {
this.wallet = WAL.accessContext.initWallet(getWalletProviders()[0]);
....
}
render() {
return (
<div>
<button onClick={this.connect}>Connect</button>
<br />
</div>
);
}
}
I get the following error
Unhandled Rejection (TypeError): Cannot set property 'wallet' of undefined
I understand that error, but I'm not sure what the correct pattern to use here is. I only want to set that value value when connect() is run.
I don't want to initialize the object to some garbage and then replace it ether. Feel like I'm missing something obvious here.
connect? Do you have an instance of the class that you're using it with?onClick={() => this.connect()}instead ofonClick={this.connect}. I think it should fix your context problem.