Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement connectFormArray HOC and FormArray component #26

Open
MaurizioVacca opened this issue Jul 5, 2019 · 2 comments
Open

Implement connectFormArray HOC and FormArray component #26

MaurizioVacca opened this issue Jul 5, 2019 · 2 comments
Labels
enhancement New feature or request
Projects

Comments

@MaurizioVacca
Copy link
Contributor

No description provided.

@slv
Copy link
Member

slv commented Jul 5, 2019

children renderProp inside FieldArray provides array helpers, and FieldArrayMap is already an array mapper, and it provides a Context so you can implement Field like any other top level field:

<FieldArray name="friends">
  {({ add }) => (
    <div>
      <FieldArrayMap>
        {({ index, values, emitChange, removeArrayItem })=> (
          <div key={index}>
            <Field
              name="first_name"
              value={values.first_name}
              onChange={e => emitChange('first_name', e.target.value)} />
            <button onClick={removeArrayItem}>Remove</button>
          </div>
        )}
      </FieldArrayMap>
      <button onClick={add}>Add Friend</button>
    </div>
  )}
</FieldArray>

@MaurizioVacca
Copy link
Contributor Author

When doing this with HOC approach (assuming we want to support it), we would need two HOC fieldArrayHOC and fieldArrayMapHOC.

The fieldArrayHOC will have a signature similar to connectForm:

const FieldArray = fieldArrayHOC(myArray)(myComponent)

while the mapper will probably need only the target Component:

const FieldArrayMap = fieldArrayMapHOC(myComponent)

nesting order when using this approach needs to be documented in details, otherwise I'm afraid that using the "HOC-way" may results confusing. What do you think?

@slv slv added this to To do in Core Jul 11, 2019
@slv slv added the enhancement New feature or request label Jul 11, 2019
@slv slv added this to the FieldScope / FieldArray milestone Jul 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Core
  
To do
Development

No branches or pull requests

2 participants