如何使用 FieldArray 评估当前字段值?

How to evaluate the current field value using a FieldArray?

是否可以在使用 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 实现?

我想fields.get(index)就是您要找的答案。