gpt4 book ai didi

javascript - React-native formik 表单引用始终为空

转载 作者:行者123 更新时间:2023-11-29 05:32:17 24 4
gpt4 key购买 nike

我有一个带有 TextInput 和 Text 的组件:

const InputWithMessage = ({ label, formikProps, formikKey,ref, ...rest }) => {
if (formikProps.touched[formikKey] && formikProps.errors[formikKey]) {
styles.inputStyles.borderColor = 'red';
}
return (
<View style={styles.inputStyles}>
<TextField
lineWidth={0}
activeLineWidth={0}
style={styles.textFieldStyles}
label={label}
ref={ref}
tintColor={
formikProps.touched[formikKey] && formikProps.errors[formikKey]
? colors.red
: colors.primary
}
onChangeText={e => formikProps.setFieldValue(formikKey, e)}
onBlur={formikProps.handleBlur(formikKey)}
{...rest}
/> .....

该组件以 formik 形式使用,并带有 refs 从一个输入到另一个输入:

<View style={{width: '50%',marginRight: 1}}>
<InputWithMessage
formikProps={formikProps}
formikKey="firstName"
value={formikProps.values.firstName}
placeholder="Prénom*"
returnKeyType="next"
ref={this.firstName}
onSubmitEditing={() => {
this.birthName.current.focus()
}}
blurOnSubmit={false}
keyboardType='default'
autoFocus
/> ....

我在构造函数中像这样推送我的引用:this.birthName = React.createRef();

除了我的梦想一直都是空的,所以无法集中注意力......

有什么想法吗?

最佳答案

我认为您的焦点调用不正确,您需要链接到当前的根。

所以在你的 onSubmitEditing 里面你需要

this.birthName.current._root.focus();

关于javascript - React-native formik 表单引用始终为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57430208/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com