import React, { Component, PropTypes } from 'react'
import { reduxForm } from 'redux-form'
export const fields = [ 'firstName', 'lastName', 'email', 'sex', 'favoriteColor', 'employed', 'notes' ]
class SimpleForm extends Component {
render() {
const {
fields: { firstName, lastName, email, sex, favoriteColor, employed, notes },
handleSubmit,
resetForm,
submitting
} = this.props
return (<form onSubmit={handleSubmit}>
<div>
<label>First Name</label>
<div>
<input type="text" placeholder="First Name" {...firstName}/>
</div>
</div>
<div>
<label>Last Name</label>
<div>
<input type="text" placeholder="Last Name" {...lastName}/>
</div>
</div>
<div>
這是redux-form
包中的Simple Form
示例。我很困惑變量firstName
來自哪裏。有沒有我從ES6語法中遺漏的東西?輔助變換形式變量
它來自'this.props.fields.firstName' https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators底部/ Destructuring_assignment – zerkms