Created
December 9, 2015 13:45
-
-
Save alpacaaa/b7f3674d122396577223 to your computer and use it in GitHub Desktop.
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 characters
import React from 'react'; | |
import { render } from 'react-dom'; | |
import yup from 'yup'; | |
import Form from 'react-formal'; | |
const schema = yup.object({ | |
test: yup.string() | |
}); | |
const ExampleForm = (props) => { | |
return ( | |
<Form | |
schema={schema} | |
defaultValue={schema.default()} | |
onSubmit={props.onSubmit} | |
> | |
<Form.Field name="test" /> | |
<Form.Button type="submit">Submit</Form.Button> | |
</Form> | |
); | |
} | |
const Loader = () => (<div>Loading...</div>); | |
const App = React.createClass({ | |
getInitialState: () => ({ | |
isLoading: false | |
}), | |
onSubmit() { | |
this.setState({ isLoading: true }); | |
}, | |
render() { | |
return ( | |
<div> | |
<p>Having fun removing the form from the DOM onSubmit.</p> | |
{this.state.isLoading ? <Loader /> : <ExampleForm onSubmit={this.onSubmit} />} | |
</div> | |
) | |
} | |
}) | |
render(<App />, document.getElementById('root')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment