import React from 'react'
import PropTypes from 'prop-types'

//

class FieldApi extends React.Component {
  render () {
    const { render, component, children, field, ...rest } = this.props

    const {
      formApi,
    } = this.context

    // Get the full field name
    const fullField = formApi.getFullField(field)

    // Get the node of that field
    const node = formApi.getNodeByField(fullField)

    // Get the field state and api
    const fieldApi = node ? node.api : {}
    const fieldState = node ? node.getState() : {}

    const inlineProps = {
      ...fieldApi,
      ...fieldState,
      ...rest,
    }

    const componentProps = {
      fieldApi: {
        ...fieldApi,
        ...fieldState,
      },
      ...rest,
    }

    if (component) {
      return React.createElement(component, componentProps, children)
    }
    if (render) {
      return render(inlineProps)
    }
    // There's no reason for form api to simply return it's children, so only
    // support a child function
    return children(inlineProps)
  }
}

FieldApi.contextTypes = {
  formApi: PropTypes.object,
}

export default FieldApi

@@ -201,22 +201,16 @@
 st %7B
-%0A     
  formApi
 ,%0A  
@@ -205,21 +205,16 @@
  formApi
-,%0A   
  %7D = thi
@@ -417,18 +417,8 @@
 eld 
-state and 
 api%0A
@@ -463,53 +463,349 @@
  %7B%7D%0A
-    const fieldState = node ? node.getState()
+%0A    // Get the field values%0A    const fieldState = node%0A      ? %7B%0A        fieldName: fullField,%0A        value: formApi.getValue(fullField),%0A        touched: formApi.getTouched(fullField),%0A        error: formApi.getError(fullField),%0A        warning: formApi.getWarning(fullField),%0A        success: formApi.getSuccess(fullField)%0A      %7D%0A     
  : %7B
@@ -878,33 +878,32 @@
 e,%0A      ...rest
-,
 %0A    %7D%0A%0A    cons
@@ -979,25 +979,24 @@
 ..fieldState
-,
 %0A      %7D,%0A  
@@ -1006,17 +1006,16 @@
  ...rest
-,
 %0A    %7D%0A%0A
@@ -1371,17 +1371,16 @@
 s.object
-,
 %0A%7D%0A%0Aexpo

Fix FieldApi component