How I can serialize data in react ?
<form method="post" action="/insert" onSubmit={(e)=>this.addMysql(e)}>
<label>Username</label>
<input type="text" id="username" name="nameUser"/>
<label>Password</label>
<input type="text" id="password" name="passs"/>
<button type="submit" type="submit">Dodaj</button>
</form>
This is my function
addMysql(event){
console.log(event.targe) //this outputs an empty form
event.preventDefault();
}
I dont want use State. Just onSubmit send all form data to AddMysql
https://medium.com/@snirlugassy/generic-input-handler-with-react-js-44a97e22cd0d
Thanks Sag1v
I suggest you use states because that is the Reacty way. if not, I may suggest a few things.
Normally I would have suggested to use FormData API, but it is not supported by IE and older browsers.
I think this answer should get you going, because its a plain JS version of serialize.
Finnally serialize if you're using jQuery, which I think you're not or you're not supposed to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With