ContactForm.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // @flow
  2. import { createStore, combineReducers } from 'redux';
  3. import { reducer as formReducer, reduxForm } from 'redux-form';
  4. import React, { Component } from 'react';
  5. import logo from './logo.svg';
  6. import './App.css';
  7. import { domOnlyProps } from './redux_form';
  8. const reducers = {
  9. form: formReducer,
  10. };
  11. const reducer = combineReducers(reducers);
  12. const store = createStore(reducer);
  13. type Props = {
  14. fields: Object,
  15. handleSubmit: Function
  16. };
  17. type State = {
  18. };
  19. let ContactForm = class extends Component<Props, State> {
  20. render() {
  21. const {
  22. fields: { firstName, lastName, email },
  23. handleSubmit,
  24. } = this.props;
  25. return (
  26. <div className="app">
  27. <header className="App-header">
  28. <img src={logo} className="App-logo" alt="logo" />
  29. <h1 className="App-title">Welcome to React with Redux-Form</h1>
  30. </header>
  31. <form className="App-intro" onSubmit={handleSubmit}>
  32. <div>
  33. <label htmlFor="first">First name</label>
  34. <input id="first" type="text" placeholder="First Name" autoComplete="given-name" {...domOnlyProps(firstName) } />
  35. </div>
  36. <div>
  37. <label htmlFor="last">Last name</label>
  38. <input id="last" type="text" placeholder="Last Name" autoComplete="family-name" {...domOnlyProps(lastName) } />
  39. </div>
  40. <div>
  41. <label htmlFor="email">Email</label>
  42. <input id="email" type="email" placeholder="Email" autoComplete="email" {...domOnlyProps(email) } />
  43. </div>
  44. <button type="submit">Submit</button>
  45. </form>
  46. </div>
  47. );
  48. }
  49. };
  50. ContactForm = reduxForm({
  51. form: 'contact', // unique name for this form
  52. fields: [
  53. 'firstName',
  54. 'lastName',
  55. 'email',
  56. ],
  57. store,
  58. })(ContactForm);
  59. export default ContactForm;