<TextField
onChange={props.onChangeTextField}
ref="questionInput"
style={styles.textField}
value={props.existingValue}
fullWidth={true}
/>
我试图在无状态功能组件中提供一个输入字段,以便在组件加载时能够聚焦它:
componentWillMount = () => {
this.refs.questionInput.focus();
console.log('test')
}
}
但我得到了错误:
Stateless function components cannot have refs.
那么有没有办法在没有 ref 的情况下在 React 中聚焦输入字段?