使用FieldArray
时是否可以获取字段的当前值?例如,我有以下代码:
import React from 'react';
import { Form, ArrayField, reduxForm } from 'redux-form';
import { Container, Row, Col } from 'reactstrap';
import { connect } from 'react-redux';
const mapStateToProps = (state) => ({
initialValues: {
customers: state.currentOffice.customers
}
});
const renderCustomers = (fields, meta) => (
<Container>
{
fields.map((customer, index) => (
<Row>
<Col lg='6'>
<span>{ /* I need the current customer name be shown here */ }</span>
<Field
name={`${customer}.name`}
component='input'
className='form-control'
/>
</Col>
</Row>
))
}
</Container>
);
const MyForm = reduxForm({ form: 'customersForm' })((props) => (
<Form onSubmit={(e) => e.preventDefault()}>
<FieldArray name='customers' component={renderCustomers} />
</Form>
));
export default connect(mapStateToProps)(MyForm);
我需要在第18行显示客户名称,但是当我尝试评估JSX花括号之间的客户名称时,我会收到字面上的customers[0].name
。
是否可以使用redux-form实现?