-
-
Notifications
You must be signed in to change notification settings - Fork 455
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
refactoring: Migrate to new lifecycle methods, close #288 #291
Conversation
有种把 vue 里面 watch 改为 computed 的感觉... |
Codecov Report
@@ Coverage Diff @@
## master #291 +/- ##
==========================================
- Coverage 99.66% 99.64% -0.02%
==========================================
Files 8 8
Lines 297 285 -12
Branches 76 74 -2
==========================================
- Hits 296 284 -12
Misses 1 1
Continue to review full report at Codecov.
|
src/DropdownMenu.jsx
Outdated
componentWillMount() { | ||
this.lastInputValue = this.props.inputValue; | ||
constructor(props) { | ||
super(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super(props)
src/Select.jsx
Outdated
open, | ||
optionsInfo, | ||
// mark defaultValue has been setted, propr.defaultValue only work at the first time. | ||
canUseDefaultValue: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.state = {
value: props.defaultValue
}
就不需要 canUseDefaultValue
了吧。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getDerivedStateFromProps
这个方法在初始化和 props 变化的时候都会被调用,为了把赋值的相关逻辑都统一放到那里面去处理,所以加了 canUseDefaultValue
。理论上也是可以把 defaultValue 相关的逻辑放到 constructor 里面的,但是有的逻辑(主要是 inputValue 初始化的逻辑)就需要在 constructor 和 getDerivedStateFromProps 里面都写一下了。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在 constructor
里用 defaultValue
来初始化 value
,然后后面都是用 prevState.value
吧,value = 'value' in nextProps.value ? nextProps.value : prevState.value
这样。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
ant-design/ant-design#9792