【发布时间】:2021-05-21 03:05:11
【问题描述】:
当满足以下条件时,我需要确保输入元素是焦点:
- DOM 可用并且
- 属性已更改
问题:我需要将我的代码放在componentDidUpdate 和componentDidMount 中还是只需componentDidUpdate 就足够了?
private makeSureInputElementFocused() {
if (this.props.shouldGetInputElementFocused && this.inputElement !== null) {
this.inputElement.focus();
}
}
componentDidMount() {
this.makeSureInputElementFocused(); // <-- do i need this?
}
componentDidUpdate() {
this.makeSureInputElementFocused();
}
【问题讨论】:
标签: reactjs