withData([mapDataToProps])

It's basically a simplified & scoped convenient wrapper for react-redux's connect.
It helps to provide form data to any React component.

Arguments

  1. mapDataToProps (Function?): A function that maps the form data to the component props. It has the signature (data, ownProps) => Object. By default it passes the whole form data as the data prop. ownProps refers to the props passed to the enhanced component itself. ownProps also contains the formId as well as the isFormValid which is also passed to asSubmit.

Returns

(Function) HoC that is used to apply the data mapping

Example

import React from 'react'
import { withData } from 'react-controlled-form'

function User({ firstname, lastname, email }) {
  return (
    <div>
      <span>Name: {firstname} {lastname}</span>
      <span>Mail: {email}</span>
    </div>
  )
}

const mapDataToProps = ({ firstname, lastname, email }) => ({
  firstname: firstname.value,
  lastname: lastname.value,
  email: email.value
})

export default withData(mapDataToProps)(User)

results matching ""

    No results matching ""