Forked from siakaramalegos/UncontrolledSerializedForm.js
Created
October 26, 2017 20:49
-
-
Save hemepositive/ffe7c540b9483bdb3db5f0cfd16a412d to your computer and use it in GitHub Desktop.
Revisions
-
siakaramalegos revised this gist
Jun 2, 2017 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,5 @@ import React, { Component } from 'react' // Import the serialize function from the form-serialize package import serialize from 'form-serialize' export default class UncontrolledSerialized extends Component { -
siakaramalegos created this gist
Jun 2, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ import React, { Component } from 'react' import serialize from 'form-serialize' export default class UncontrolledSerialized extends Component { onSubmit = (e) => { e.preventDefault() // Usually, we would pass the final input values to a function that // would do something with the data like persist it to a database. // Using serialization, we just need to pass that function the // serialized form body. const form = e.currentTarget const body = serialize(form, {hash: true, empty: true}) console.log(body) } render() { // Let's see when re-renders happen. console.log('render!') return ( <form onSubmit={this.onSubmit}> <h1>Uncontrolled Inputs + Form Serialization Example</h1> <label> Name <input name="firstName" /> </label> <label> Spirit Animal <input name="spiritAnimal" /> </label> <button>Submit</button> </form> ) } }