【发布时间】:2020-07-06 00:38:32
【问题描述】:
我正在尝试在 react-native 中创建一个全局 onchange 处理程序 但它没有将我的电子邮件和密码的值设置为我输入的任何内容 我试过在谷歌上搜索,但大多数例子都是基于 react.js 而不是 react-native 我会立即获得帮助
import React, {useState} from 'react';
import {View, Text, Button, TextInput} from 'react-native';
import style from './Style';
export default function Login() {
const [authDetails, setAuthDetails] = useState({
email: '',
password: '',
});
const {email, password} = authDetails;
const onChange = text =>
setAuthDetails({
...authDetails,
email: text.email,
password: text.name,
});
const login = () => {
console.log('EMAIL=', email, '\n', 'password =', password);
};
return (
<View>
<TextInput
name="email"
placeholder="Email"
onChangeText={onChange}
value={email}
/>
<TextInput
name="password"
placeholder="Password"
onChangeText={onChange}
value={password}
/>
<Button title="Login" onPress={login} />
</View>
);
}
【问题讨论】:
标签: javascript react-native onchange use-state