【发布时间】:2019-08-14 13:12:03
【问题描述】:
我正在尝试学习钩子并在一般情况下做出原生反应。
目前我正在尝试创建一个小型购物清单应用程序,您可以在其中将所需物品添加到列表中。
我已经在显示屏上有输入 + 按钮。
<View>
<TextInput placeholder="hinzufügen..."
onChangeText={inputHandler}
value={enteredEntity}
/>
<Button title="+" onPress={addInputHandler} />
</View>
我有两个函数+钩子声明如下:
const [enteredEntity, setEnteredEntity] = useState('');
const inputHandler = (enteredEntity) => {
setEnteredEntity(enteredEntity);
}
const addInputHandler = () => {
console.log(enteredEntity);
}
并得到以下错误消息(见下文) - 在第 20 行,错误应该是我有 TextInput。
非常感谢您的意见。
【问题讨论】:
-
请显示整个代码。你导入了useState吗?
import React, { useState } from 'react' -
谢谢伊恩,这为我解决了这个问题。我完全错过了导入。
-
从'react'导入反应,{useState}
标签: android reactjs react-native react-hooks