Skip to content

Instantly share code, notes, and snippets.

@alpacaaa
Created December 9, 2015 13:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alpacaaa/b7f3674d122396577223 to your computer and use it in GitHub Desktop.
Save alpacaaa/b7f3674d122396577223 to your computer and use it in GitHub Desktop.
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