Skip to content

condition/render can't work with dependencies in antd v5 #8

@andyyxw

Description

@andyyxw

image
Field Condition示例中使用useWatch监听了favoriteFruit字段,导致整个form都跟随favoriteFruit在rerender。
antd v5中有dependencies / shouldUpdate可以使某个表单项只依赖部分表单项,可减少render次数以提高性能,但是发现这种方式目前NiceForm并不支持:

{
  key: 'otherFruit',
  label: 'Other',
  dependencies: ['favoriteFruit'],
  condition: () => NiceForm.getFieldValue('favoriteFruit', meta, form) === 'Other',
}

源码中condition逻辑是在FormField中,实际上只会在整个form render 时执行:
image
可以将condition / render逻辑转移到adapter中的renderField,但这样对 adapter 是 breaking change
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions