当我在react-native中隐藏密码时,密码冻结到开头

ix0qys7i  于 2022-12-14  发布在  React
关注(0)|答案(1)|浏览(129)
const [password, setPassword] = useState('')
const [passwordVisibility, setPasswordVisibility] = useState(false);
<View style={styles.inputContainer}>
          <TextInput
            name="password"
            style={styles.inputField}
            autoCapitalize='none'
            value={password}
            autoCorrect={false}
            textContentType="newPassword"
            onChangeText={onChangeText}
            placeholder="Password"
            enablesReturnKeyAutomatically
            secureTextEntry={passwordVisibility}
          />
          <Pressable onPress={()=>{setPasswordVisibility(!passwordVisibility) , console.log(password)}}>
          <Icon name={passwordVisibility == true ? 'eye' : 'eye-off' } size={23} color='purple' />
          </Pressable>
          
        </View>

这是我的代码。当我在react-native中隐藏我的密码时,密码冻结在开头。我该如何修复这个问题

hyrbngr7

hyrbngr71#

试试换
onChangeText={onChangeText}onChangeText={value => setPassword(value)}
并将password赋给TextInput上的值prop

<TextInput

  // current props

  onChangeText={value => setPassword(value)}
  value={password}
/>

相关问题