fix: maximum depth exceeded should no longer occur (#408)

This commit is contained in:
Corbin Crutchley
2023-08-28 18:27:02 -07:00
committed by GitHub
parent 77594a63ba
commit 0b5c94d364

View File

@@ -125,10 +125,6 @@ export class FieldApi<TData, TFormData> {
? state.meta.error ? state.meta.error
: undefined : undefined
if (state.value !== this.prevState.value) {
this.validate('change', state.value as never)
}
this.prevState = state this.prevState = state
this.state = state this.state = state
}, },
@@ -206,17 +202,13 @@ export class FieldApi<TData, TFormData> {
getValue = (): typeof this._tdata => { getValue = (): typeof this._tdata => {
return this.form.getFieldValue(this.name) return this.form.getFieldValue(this.name)
} }
setValue = ( setValue = (
updater: Updater<typeof this._tdata>, updater: Updater<typeof this._tdata>,
options?: { touch?: boolean; notify?: boolean }, options?: { touch?: boolean; notify?: boolean },
) => { ) => {
this.form.setFieldValue(this.name, updater as any, options) this.form.setFieldValue(this.name, updater as never, options)
this.store.setState((prev) => { this.validate('change', this.state.value)
return {
...prev,
value: updater as any,
}
})
} }
getMeta = (): FieldMeta => this.form.getFieldMeta(this.name) getMeta = (): FieldMeta => this.form.getFieldMeta(this.name)
@@ -250,7 +242,7 @@ export class FieldApi<TData, TFormData> {
form: this.form, form: this.form,
}) })
validateSync = async (value = this.state.value, cause: ValidationCause) => { validateSync = (value = this.state.value, cause: ValidationCause) => {
const { onChange, onBlur } = this.options const { onChange, onBlur } = this.options
const validate = const validate =
cause === 'submit' ? undefined : cause === 'change' ? onChange : onBlur cause === 'submit' ? undefined : cause === 'change' ? onChange : onBlur