import React from 'react'; import ReactDOM from 'react-dom'; import Formsy from 'formsy-react'; import MyCheckbox from './../components/Checkbox'; import MyInput from './../components/Input'; import MySelect from './../components/Select'; const user = { name: 'Sam', free: true, hair: 'brown' }; const randomNames = ['Christian', 'Dmitry', 'Aesop']; const randomFree = [true, false]; const randomHair = ['brown', 'black', 'blonde', 'red']; class App extends React.Component { constructor(props) { super(props); this.randomize = this.randomize.bind(this); this.submit = this.submit.bind(this); } randomize() { const random = { name: randomNames[Math.floor(Math.random()*randomNames.length)], free: randomFree[Math.floor(Math.random()*randomFree.length)], hair: randomHair[Math.floor(Math.random()*randomHair.length)], }; this.form.reset(random); } submit(data) { alert(JSON.stringify(data, null, 4)); } render() { return ( this.form = c} onSubmit={this.submit} onReset={this.reset} className="form" >
); } } ReactDOM.render(, document.getElementById('example'));