Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript 什么';s文本输入目标值的类型_Typescript_React Native_React Hooks - Fatal编程技术网

Typescript 什么';s文本输入目标值的类型

Typescript 什么';s文本输入目标值的类型,typescript,react-native,react-hooks,Typescript,React Native,React Hooks,如果使用以下代码基 import React, { useState } from 'react'; import { TextInput } from 'react-native'; export function LoginInput() { const [text, setText] = useState(''); function handlerTextChange(e) { setText(e.target.value) } return ( &l

如果使用以下代码基

import React, { useState } from 'react';
import { TextInput } from 'react-native';

export function LoginInput() {
  const [text, setText] = useState('');

  function handlerTextChange(e) {
    setText(e.target.value)
  }

  return (
    <TextInput
      style={{ height: 40 }}
      value={text}
      onChangeText={handleTextChange}
    />
  )
}
import React,{useState}来自“React”;
从“react native”导入{TextInput};
导出函数LoginInput(){
const[text,setText]=useState(“”);
函数handlerTextChange(e){
setText(例如target.value)
}
返回(
)
}

如何定义e的类型,它是事件类型还是任意类型?

在使用onChange时,必须使用e.target.value,其中e本机事件,而e.target.value是字符串

对于获取文本,请仅使用如下方式的onChangeText

<TextInput
    style={{height: 40, borderColor: 'gray', borderWidth: 1}}
    onChangeText={(text) => this.setState({text})}
    value={this.state.text}
/>
this.setState({text})}
值={this.state.text}
/>
其中,文本仅为字符串


查看一下在使用onChange时,您必须使用e.target.value,其中e本机事件,e.target.value是字符串

对于获取文本,请仅使用如下方式的onChangeText

<TextInput
    style={{height: 40, borderColor: 'gray', borderWidth: 1}}
    onChangeText={(text) => this.setState({text})}
    value={this.state.text}
/>
this.setState({text})}
值={this.state.text}
/>
其中,文本仅为字符串


查看一下,您输入的值将被提供。因此,类型是字符串值

import React,{Component}来自'React';
从“react native”导入{View,StyleSheet,TextInput};
从“expo”导入{Constants};
导出默认类应用程序扩展组件{
状态={
输入值:“”,
};
handlerTextChange=inputValue=>{
console.log(inputValue)//输入的字符串
console.log(输入值的类型)//字符串
this.setState({inputValue});
};
render(){
返回(
);
}
}
const styles=StyleSheet.create({
容器:{
弹性:1,
对齐项目:“居中”,
为内容辩护:“中心”,
paddingTop:Constants.statusBarHeight,
背景颜色:“#fff”,
},
});

将提供您输入的值。因此,类型是字符串值

import React,{Component}来自'React';
从“react native”导入{View,StyleSheet,TextInput};
从“expo”导入{Constants};
导出默认类应用程序扩展组件{
状态={
输入值:“”,
};
handlerTextChange=inputValue=>{
console.log(inputValue)//输入的字符串
console.log(输入值的类型)//字符串
this.setState({inputValue});
};
render(){
返回(
);
}
}
const styles=StyleSheet.create({
容器:{
弹性:1,
对齐项目:“居中”,
为内容辩护:“中心”,
paddingTop:Constants.statusBarHeight,
背景颜色:“#fff”,
},
});

onChangeText
直接为您提供
更改后的文本
onChangeText={(text)=>handleTextChange(text)}
onChangeText
直接为您提供
已更改的文本
onChangeText={(text)=>handleTextChange(text)}