Getting this error in onSubmit() function.
this is not accessible within onSubmit() function.
I have also added this.onSubmit = this.onSubmit.bind(this);
but still it is not working.
Code :
...
class CamapaignNew extends Component {
constructor(props) {
super(props);
this.state = {minimumContribution : ''};
this.onSubmit = this.onSubmit.bind(this)
}
onSubmit = async (event) => {
event.preventDefault();
const accounts = await web3.eth.getAccounts();
console.log(this);
const minC = this.state.minimumContribution;
await factory.methods.createCampaign(minC).send({
from: accounts[0]
});
}
render() {
return (
...
<Form onSubmit={this.onSubmit}>
<Form.Field>
<label>Minimum Contribution</label>
<Input
label="wei"
labelPosition='right'
value={this.state.minimumContribution}
onChange={(event) => {this.setState({ minimumContribution: event.target.value })}}
/>
</Form.Field>
<Button primary>Create!</Button>
</Form>
...
}
}
Thank you in advance.