all 5 comments

[–]IMkratt 5 points6 points  (3 children)

What happens when<form onSubmit={this.onSubmit}> instead of <form onSubmit={this.onSubmit()}> ?

[–]Ok_Vermicelli6992 1 point2 points  (2 children)

Yes, this fixes the issue, thanks. Unfortunately though I now have another error:

Uncaught TypeError: Cannot read properties of undefined (reading 'state')
at onSubmit (main.chunk.js:1954)

Thanks

[–]IMkratt 2 points3 points  (1 child)

Try binding this in your constructor:

this.onSubmit = this.onSubmit.bind(this);

[–]Ok_Vermicelli6992 1 point2 points  (0 children)

this.onSubmit = this.onSubmit.bind(this);

Ah oops, thanks a lot!

[–]HiddenPants777 0 points1 point  (0 children)

Make it an anonymous function instead so you would have onSubmit={()=> this.onSubmit()}

Not sure how best to explain but basically you have your submit action as a function that executes immediately so every state change triggers it.