未定义不是对象 [React Native]
我在文本输入方面遇到了一些小问题。
我有一个带有 3 个文本输入的屏幕,每个输入都有自己的状态。当我尝试捕获用户输入的值并将其保存在状态中时,会出现问题,但我有“未定义不是 setState 中的对象”。我阅读了各种帖子,并尝试了这些解决方案,但我仍然保留着这个问题。
这里我把我的想法拆下来。
//这里我从另一个屏幕发送的道具中声明状态“Nombre”
const [stateNombre, setStateNombre] = useState(JSON.stringify(param_nombre));
//这里我声明TextInput
<TextInput
id="text_nombre"
placeholder={"Nombre"}
style={styles.data_input}
autoCorrect={false}
blurOnSubmit
placeholderTextColor="#777"
autoCapitalized="words"
multiline={true}
onChangeText={text => this.setStateNombre(text.target.value)}
></TextInput>
//这里问题的图片
I'm with little issues with text inputs.
I have a screen with 3 text inputs, each have his own state. The problem occurs when I try to capture the value enter from the user and save it in a state, but i have "undefined is not an object in the setState". I read various threads, and I tried those solves, but I still keeping that problem.
Here I detach how I thought.
//Here I declare the state "Nombre" from a props sending by another screen
const [stateNombre, setStateNombre] = useState(JSON.stringify(param_nombre));
//Here I declare the TextInput
<TextInput
id="text_nombre"
placeholder={"Nombre"}
style={styles.data_input}
autoCorrect={false}
blurOnSubmit
placeholderTextColor="#777"
autoCapitalized="words"
multiline={true}
onChangeText={text => this.setStateNombre(text.target.value)}
></TextInput>
//Here a picture of the problem
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来您将类组件和功能组件组合在一起
为什么我说你使用来自功能组件的
useState
和来自类组件 + 功能组件的this.setStateNombre
。它是某种奇怪的代码。当涉及到您的 Problem First
log(JSON.stringify(param_nombre))
和 For TextInput [组件和不受控制的组件]
It seems you are combined both Class Components and Functional components Together
Why I am Saying your Using
useState
from Functional components andthis.setStateNombre
from Class Components + Functional components.Its some kind of weird code.when it comes to your Problem First
log(JSON.stringify(param_nombre))
and For TextInput [components and uncontrolled components]