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

Removes redundant dependencies in append and remove of useFieldArray #2780

Merged
merged 3 commits into from Sep 1, 2020
Merged

Removes redundant dependencies in append and remove of useFieldArray #2780

merged 3 commits into from Sep 1, 2020

Conversation

michalbundyra
Copy link
Contributor

@michalbundyra michalbundyra commented Aug 31, 2020

Fixes #2773

In append method fillEmptyArray cares just about the length of the array, so the fields dep was not needed there at all.

In remove dependency fields was not used.

All tests are still green. Probably we should add some test cases, so these dependencies are not re-added to the methods in useFieldArray.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Aug 31, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 2abef78:

Sandbox Source
react-hook-form/react-hook-form: app Configuration
React Hook Form - useFieldArray (forked) Issue #2773
react-hook-form-v6-setValue (forked) Issue #2773

@bluebill1049
Copy link
Member

hmmm actually I am going to hold this PR, I think to remove that ref object is the correct approach.

@react-hook-form react-hook-form deleted a comment from michalbundyra Aug 31, 2020
@michalbundyra
Copy link
Contributor Author

@bluebill1049

hmmm actually I am going to hold this PR, I think to remove that ref object is the correct approach

Ok, I believe you will find a better way to eliminate this dependency, as it is not needed in prepend as well. Thanks.

src/useFieldArray.ts Outdated Show resolved Hide resolved
append: React.useCallback(append, [name, errors, fields]),
remove: React.useCallback(remove, [name, errors, fields]),
append: React.useCallback(append, [name, errors]),
remove: React.useCallback(remove, [name, errors]),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please fix remove as well with ref.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was not used, as you see all tests are still green. Unless I am missing something?

I am not sure also where errors dep is used in these functions? Maybe it can be removed as well?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right, that was my bad!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want me to remove errors dep as well. then?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's used in batchStateUpdate.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will clean this update to only have name as dep. you can leave that to me, will sort out tonight.

Copy link
Member

@bluebill1049 bluebill1049 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR.

michalbundyra and others added 2 commits September 1, 2020 06:40
Co-authored-by: Bill <bluebill1049@hotmail.com>
@bluebill1049
Copy link
Member

dame lint failed, you may have to pull the latest and run yarn lint. thanks

@michalbundyra
Copy link
Contributor Author

@bluebill1049

dame lint failed

Fixed! :)

@bluebill1049 bluebill1049 merged commit 279741c into react-hook-form:master Sep 1, 2020
@michalbundyra michalbundyra deleted the bugfix/redundant-deps-useFieldArray branch September 1, 2020 05:58
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.

Methods of use useFieldArray triggers hooks
2 participants