1

Getting this error in onSubmit() function.

enter image description here

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.

  • Does this answer your question? [Binding vs Arrow-function (in JavaScript, or for react onClick)](https://stackoverflow.com/questions/50375440/binding-vs-arrow-function-in-javascript-or-for-react-onclick) – Fiodorov Andrei Jan 26 '22 at 08:41
  • Shouldn't you have something like `const [state, setState] = useState({minimumContribution: ''})`? – GACy20 Jan 26 '22 at 08:58
  • Its not using functional component @GACy20 – olscode Jan 26 '22 at 09:03
  • Fortunately, I got the solution from https://stackoverflow.com/questions/60595506/async-await-not-working-on-states-from-usestates-of-react – Roshan Gupta Jan 29 '22 at 16:53

0 Answers0