我有一个常数,它的初始值为
const [userProfileDataFetched, setUserProfileData] = useState('')
上述的初始值需要设置为另一个常量:
const [profileData, setProfileData] = useState({
name: {
value: userProfileDataFetched.name, //Issus here: This is initial value right, this should change later ? If i write it like value= "some text" it works. This doesn't work
validation: ['blank', 'name'],
errorMsg: nameErrorMsg,
errorKey: 'ename',
}
这是文本输入:
<TextInput
placeholderTextColor={errors.ename ? ThemeColors.themeRed : ThemeColors.darkGrey}
style={styles.input}
name={lang.name}
value={profileData.name.value}
onChangeText={text =>
setProfileData({
...profileData,
...{
name: {
value:text, //UPDATED
validation: ['blank', 'name'],
errorMsg: nameErrorMsg,
errorKey: 'ename',
},
},
})
}
/>
在React Native中,更改后的文本作为单个字符串参数传递给回调处理程序。所以,与其这么做onChangetext={e=>console.log(e.target.value}
你会的CCD_ 2。