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

Form setFieldsValue 方法参数是什么,我传入一个对象,在componentWillReceiveProps中执行死机了 #2985

Closed
Sean-Snow opened this Issue Sep 9, 2016 · 15 comments

Comments

Projects
None yet
9 participants
@Sean-Snow
Copy link

Sean-Snow commented Sep 9, 2016

  • antd 版本: 1.11.0
  • 操作系统及其版本:MAC 10.11.6 内存16G CPU i7
  • 浏览器及其版本: CHROME

点击一个编辑按钮,使用现有的数据填充表单。

在点击按钮的时候update state 为编辑状态,
在componentWillReceiveProps中调用setFieldsValue方法。大概1分钟左右以后表单填充完成,
然后我在点击任意Input,继续等待1分钟左右。

@benjycui

This comment has been minimized.

Copy link
Contributor

benjycui commented Sep 10, 2016

setFieldsValue 本质是调用外层 wrapper 的 setState,间接调用 componentWillReceiveProps,所以死循环了。

请用 mapPropsToFields http://ant.design/components/form/#Form.create(options)

benjycui added a commit that referenced this issue Sep 10, 2016

@Sean-Snow

This comment has been minimized.

Copy link
Author

Sean-Snow commented Sep 12, 2016

@benjycui 谢了

@Sean-Snow Sean-Snow closed this Sep 12, 2016

@undefinedor

This comment has been minimized.

Copy link

undefinedor commented Oct 19, 2016

mapPropsToFields 把 props 转为对应的值,可用于把 Redux store 中的值读出
Function(props): Object{ fieldName: Object{ value } }
没看到 我要在mapPropsToFields怎么写

@bnlambert

This comment has been minimized.

Copy link

bnlambert commented Dec 15, 2016

Hi, is there a way to translate this converstion?

@Sean-Snow

This comment has been minimized.

Copy link
Author

Sean-Snow commented Dec 15, 2016

@bnlambert What's your question

@bnlambert

This comment has been minimized.

Copy link

bnlambert commented Dec 15, 2016

I wish to see how to set initial values with setFieldsValue.

Also my datepicker calender is appearing in Chinese; how do I rectify it?

@Sean-Snow

This comment has been minimized.

Copy link
Author

Sean-Snow commented Dec 15, 2016

you can try moment.locale('en');

https://ant.design/components/date-picker/ doc

@bnlambert

This comment has been minimized.

Copy link

bnlambert commented Dec 15, 2016

Do I requre moment from 'antd' or I need to download it separately?.
Please be a little bit more explicit. Thanks

@coljung

This comment has been minimized.

Copy link

coljung commented Feb 13, 2017

On your website, there is this note for 'setFieldsValue'

please don't use it in componentWillReceiveProps, otherwise, it will cause an endless loop, more)

It links to this page for what i assume its an explanation. Could we get some sort of translation if possible ?

thx

@benjycui

This comment has been minimized.

Copy link
Contributor

benjycui commented Feb 14, 2017

@coljung try Google translator.

@walidvb

This comment has been minimized.

Copy link

walidvb commented Feb 16, 2018

@bnlambert @coljung or if you're on chrome, right-click -> translate to English

@ncuillery

This comment has been minimized.

Copy link

ncuillery commented Apr 9, 2018

I can understand that some issues were written in Chinese for convenient/faster communication between maintainers, but this one is referenced in the official documentation, it is "part of it" so it should be translated.
Alternative: the information written here should be included in the official documentation.

@benjycui IMO "try Google translator" is not a constructive comment and breaches some rules of conduct mentioned in CODE_OF_CONDUCT.md

  • Using welcoming and inclusive language
  • Being respectful of differing viewpoints and experiences
  • Gracefully accepting constructive criticism
  • Focusing on what is best for the community
  • Showing empathy towards other community members

To the 9 people who reacted with "😄": you are obviously bilingual, how long it would have been take to Google Translate the content, adjust the translation if needed thanks to your language skills and paste the content here instead ?

@ncuillery

This comment has been minimized.

Copy link

ncuillery commented Apr 9, 2018

That being said:

  1. the OP describes the problem: Calling setFieldsValue in componentWillReceivedProps causes a loop which eventually stops after 1 minute. Every field change causes a new "infinite" loop.
  2. the maintainer answered that setFieldsValue leads to a this.setState in the HOC, so it changes props and directly causes your componentWillReceiveProps method to be called. That's why there is a loop. We should use mapPropsToFields.
  3. the OP thanks the maintainer
  4. An other (unanswered) question is asked. mapPropsToFields is used to read data from the store, how can I write in it ?
@codepandy

This comment has been minimized.

Copy link

codepandy commented Jun 19, 2018

这form是真难用,封装后使用成本太高

@lehug

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.