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

fix(@uform/react): invariant initialValues will not be changed when form rerender #214

Merged

Conversation

monkindey
Copy link
Contributor

@monkindey monkindey commented Jul 30, 2019

Closes #211

原因在于 initialValues 在 componentDidUpdate 的时候没有收集 schema 的 default,导致 initialValues 不一致。

原因是 #214 (comment)

@@ -182,17 +182,24 @@ export const StateForm = createHOC((options, Form) => {
}

public componentDidUpdate(prevProps) {
const { value, editable, initialValues } = this.props
const { value, editable, initialValues, schema } = this.props
const calculatedInitialValues = caculateSchemaInitialValues(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么只计算当前props的intialValues,不计算prevProps的intialValues?

Copy link
Collaborator

@janryWang janryWang Aug 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里不用任何改动,仔细看一下,其实是props.initialValues引用被改动了,只需要在
https://github.com/alibaba/uform/blob/master/packages/core/src/index.ts#L30 加上clone即可,我们只需要每次对比的都是props就行了

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

values 要不要也 clone 一份?

@@ -121,7 +121,7 @@ export const caculateSchemaInitialValues = (
if (!isEmpty(value)) {
setIn(initialValues, name, value)
}
if (isFn(callback)) {
if (callback && isFn(callback)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isFn 方法的通过不是确保了 callback 会是 Function 嘛,这样还需要再先确保 callback 是存在的吗?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果没有的话就不要执行 isFn 了。

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有道理😂😂

@monkindey monkindey changed the title fix(@uform/react): calculate initialValues when form update fix(@uform/react): invariant initialValues will not be changed when form rerender Aug 1, 2019
@janryWang janryWang merged commit b9efa4c into alibaba:master Aug 2, 2019
ZirkleTsing pushed a commit that referenced this pull request May 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Form values will be clear when click the submit button
3 participants