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

onValuesChange not used in dependency list of setFieldValue (use-form-values.ts) #6392

Closed
2 tasks done
rguryanov opened this issue Jun 15, 2024 · 1 comment
Closed
2 tasks done
Labels
Fixed patch Completed issues that will be published with next patch (1.0.X)

Comments

@rguryanov
Copy link

rguryanov commented Jun 15, 2024

Dependencies check up

  • I have verified that I use latest version of all @mantine/* packages

What version of @mantine/* packages do you have in package.json?

7.10.2

What package has an issue?

@mantine/form

What framework do you use?

create-react-app (CRA)

In which browsers you can reproduce the issue?

All

Describe the bug

If you change passed onValuesChange, some events will be fired with old handler

example
const form = useForm({
mode: 'uncontrolled',
initialValues: selectedRecord as Cred,
validate: {
name: (value) => {
return true
}
},
// new handler every rerender
onValuesChange: (values) => {
// change some scoped value
setValue({
...oldScopedValue,
...values
}),
},
});

Let's see use-form-values.ts

const setValues = useCallback(...,[onValuesChange])

setValues has onValuesChange in dependency list

const setFieldValue = useCallback(..., [])
const initialize = useCallback(..., [])
const resetValues = useCallback(..., [])

setFieldValue, initialize and resetValues has empty dependency list and will use ONLY first calculated setValues

If possible, include a link to a codesandbox with a minimal reproduction

No response

Possible fix

No response

Self-service

  • I would be willing to implement a fix for this issue
@rtivital rtivital added the Fixed patch Completed issues that will be published with next patch (1.0.X) label Jun 28, 2024
@rtivital
Copy link
Member

rtivital commented Jul 2, 2024

Fixed in 7.11.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fixed patch Completed issues that will be published with next patch (1.0.X)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants