我需要确保在满足以下条件时关注输入元素:
问题:我是否需要将我的代码放入两者中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();
}
Run Code Online (Sandbox Code Playgroud) reactjs ×1