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

Add defaultValue and initialValue #98

Merged
merged 2 commits into from
Aug 15, 2019
Merged

Add defaultValue and initialValue #98

merged 2 commits into from
Aug 15, 2019

Conversation

PerfectPixel
Copy link
Contributor

@PerfectPixel PerfectPixel commented Jul 12, 2019

Hey Erik,

today I needed to set an initialValue on the array, which led to a weird workaround for me. So here the PR:

I copied the explanation from the react-final-form repository, and also added the defaultValue.

I though about checking that the values are array but then decided against it. Maybe it would make sense to pass all the other props through too?

Cheers!

@codecov
Copy link

codecov bot commented Jul 12, 2019

Codecov Report

Merging #98 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff          @@
##           master    #98   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           6      6           
  Lines          60     60           
  Branches       10     10           
=====================================
  Hits           60     60
Impacted Files Coverage Δ
src/useFieldArray.js 100% <ø> (ø) ⬆️
src/FieldArray.js 100% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 638d825...1bf88b4. Read the comment docs.

@PerfectPixel
Copy link
Contributor Author

PerfectPixel commented Jul 15, 2019

I noticed that using initialValue with useFieldArray leads to react constantly updating. Maybe you have an idea what causes it @erikras

Edit: I realized that it was an error caused by always creating new array references on render

@erikras
Copy link
Member

erikras commented Jul 15, 2019

Can you add these two to index.d.ts, too?

@PerfectPixel
Copy link
Contributor Author

PerfectPixel commented Jul 15, 2019

I could, but isn't that redundant as UseFieldArrayConfig<FieldValue> extends UseFieldConfig<FieldValue> and UseFieldConfig already contains initialValue and defaultValue 🤔

Edit:
I just checked in my typescript project, all properties of useField are also available in useArrayField within the type although only a few are passed through. Which brings me back to:

Maybe it would make sense to pass all the other props through too?

@PerfectPixel
Copy link
Contributor Author

@erikras any decision on my question above? 🙃

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@erikras erikras merged commit 16f19c5 into final-form:master Aug 15, 2019
@erikras
Copy link
Member

erikras commented Aug 15, 2019

Published in v3.1.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants