onValuesChange not used in dependency list of setFieldValue (use-form-values.ts) #6392
Closed
2 tasks done
Labels
Fixed patch
Completed issues that will be published with next patch (1.0.X)
Dependencies check up
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
mantine/packages/@mantine/form/src/hooks/use-form-values/use-form-values.ts
Line 56 in 29f24e3
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
The text was updated successfully, but these errors were encountered: