React native 为什么可以';使用钩子在react native中清除TextInput中的值?
当用户点击按钮时,我试图从文本输入中清除用户的值,但我无法得到它 我使用react native中的钩子实现这个演示 所以,请帮助我,我是react-native的新手。高级谢谢React native 为什么可以';使用钩子在react native中清除TextInput中的值?,react-native,react-native-android,react-native-ios,react-native-textinput,React Native,React Native Android,React Native Ios,React Native Textinput,当用户点击按钮时,我试图从文本输入中清除用户的值,但我无法得到它 我使用react native中的钩子实现这个演示 所以,请帮助我,我是react-native的新手。高级谢谢 import React, { useState, useEffect } from 'react'; import { StyleSheet, View, TextInput, TouchableOpacity, Text } from 'react-native'; import { RFValu
import React, { useState, useEffect } from 'react';
import { StyleSheet, View, TextInput, TouchableOpacity, Text } from 'react-native';
import { RFValue } from 'react-native-responsive-fontsize';
import { heightPercentageToDP as hp, widthPercentageToDP as wp } from 'react-native-responsive-screen';
const Login = ({ navigation }) => {
const [name, setName] = useState('');
const [password, setPassword] = useState('');
/* useEffect(() => {
console.log("login screen");
setName('');
setPassword('');
}); */
function resetTextInput () {
console.log("reset TextInput");
setName(" ");
setPassword(" ");
}
return (
<View style={styles.mainContainer}>
<Text style={styles.txtTitle}>Login</Text>
<View style={{ marginTop: 80 }}>
<TextInput
placeholder={'Username'}
style={styles.txtInput}
onChangeText={(name) => { setName(name) }}
/>
<TextInput
placeholder={'Password'}
style={styles.txtInput}
secureTextEntry={true}
onChangeText={(password) => { setPassword(password) }}
/>
</View>
<TouchableOpacity style={styles.loginBtn} onPress={()=>{resetTextInput()}}>
<Text style={styles.loginBtnTxt}>Login</Text>
</TouchableOpacity>
</View>
)
}
import React,{useState,useffect}来自“React”;
从“react native”导入{样式表、视图、文本输入、TouchableOpacity、文本};
从'react native responsive fontsize'导入{RFValue};
从“react native responsive screen”导入{heightPercentageToDP作为hp,widthPercentageToDP作为wp};
常量登录=({navigation})=>{
const[name,setName]=useState(“”);
const[password,setPassword]=useState(“”);
/*useffect(()=>{
console.log(“登录屏幕”);
集合名(“”);
设置密码(“”);
}); */
函数resetTextInput(){
日志(“重置文本输入”);
集合名(“”);
设置密码(“”);
}
返回(
登录
{setName(name)}
/>
{setPassword(password)}
/>
{resetTextInput()}}>
登录
)
}
重置值时使用空引号
function resetTextInput () {
console.log("reset TextInput");
setName('');//changed this
setPassword('');//changed this
}
并在value
prop中给出使用的各自状态
<TextInput
placeholder={'Password'}
style={styles.txtInput}
secureTextEntry={true}
onChangeText={(password) => { setPassword(password) }}
value={password}
/>
{setPassword(password)}
值={password}
/>
与第一个文本输入相同,重置值时使用空引号
function resetTextInput () {
console.log("reset TextInput");
setName('');//changed this
setPassword('');//changed this
}
并在value
prop中给出使用的各自状态
<TextInput
placeholder={'Password'}
style={styles.txtInput}
secureTextEntry={true}
onChangeText={(password) => { setPassword(password) }}
value={password}
/>
{setPassword(password)}
值={password}
/>
与第一个文本输入相同,您可以设置空值:
function resetTextInput () {
console.log("reset TextInput");
setName(null);//changed this
setPassword(null);//changed this
}
主要的是使用TextInput道具“value”设置状态值。
{setName(name)}
/>
{setPassword(password)}
/>
此解决方案将帮助您。您可以设置空值:
function resetTextInput () {
console.log("reset TextInput");
setName(null);//changed this
setPassword(null);//changed this
}
主要的是使用TextInput道具“value”设置状态值。
{setName(name)}
/>
{setPassword(password)}
/>
此解决方案将帮助您。当用户来自登录屏幕的另一屏幕时,我如何实现相同的功能?当用户来自登录屏幕的另一屏幕时,我如何实现相同的功能?