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

getFieldsValue(true) allows for direct mutation of the form store #484

Open
AndreLemay opened this issue Aug 12, 2022 · 0 comments
Open

Comments

@AndreLemay
Copy link

Repro:

Set up any basic form, and give a field an onChange like this:

() => {
    const formData = form.getFieldsValue(true)
    delete formData.nameOfField
    console.log(form.getFieldsValue(true))
}

Normally, one would expect that this should have no effect, as react/state context should be immutable, but in this case you will find that it will log an object missing the deleting field.

The problem comes from the implementation of getFieldsValue here:

field-form/src/useForm.ts

Lines 271 to 273 in d789287

if (nameList === true && !filterFunc) {
return this.store;
}

Which just returns the store object directly.

This should be following React conventions and returning a clone, as it does when a specific list of NamePaths is requested.

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

No branches or pull requests

1 participant