如何监听表单state变化来更新视图?
#3850
-
举个例子,编辑态显示保存按钮,只读态显示编辑按钮,我用下面这种方法不可行,我想知道除了自己维护一个状态,有什么办法能响应form.setState()? const SaveButton: React.FC<{ form: Required<FormProps>['form'] }> = ({
form,
}) => {
const formState = form.getState()
return (
<Button
block
size="large"
onClick={() => {
form.setState((state) => {
state.editable = !state.editable
})
}}
>
{formState.editable ? '保存' : '编辑'}
</Button>
)
} |
Beta Was this translation helpful? Give feedback.
Answered by
joyz0
Jun 8, 2023
Replies: 1 comment 1 reply
-
已解决,参考 |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
joyz0
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
已解决,参考
@formily/antd-v5
中的Submit组件实现即可。