Typescript-传播参数必须具有元组类型或传递给REST参数
我遇到了这个错误的一些问题:
A spread argument must either have a tuple type or be passed to a rest parameter.
我的代码如下所示:
const [item, setItem] = useState<string>();
const [items, setItems] = useState([]);
const handleAddItem = () => {
console.log(item);
setItems(...items, item);
}
<TouchableOpacity onPress={() => handleAddItem()}>
<View style={styles.addWrapper}>
<Text style={styles.addText}>+</Text>
</View>
</TouchableOpacity>
我已经搜索了有关此主题的其他问题,但似乎无法使用提供的任何问题来修复它。任何想法和意见表示赞赏!
I am having some problems with this error:
A spread argument must either have a tuple type or be passed to a rest parameter.
and my code looks like this:
const [item, setItem] = useState<string>();
const [items, setItems] = useState([]);
const handleAddItem = () => {
console.log(item);
setItems(...items, item);
}
<TouchableOpacity onPress={() => handleAddItem()}>
<View style={styles.addWrapper}>
<Text style={styles.addText}>+</Text>
</View>
</TouchableOpacity>
I have searched the other questions posted about this topic but could not seem to fix it with any of those provided. Any ideas and inputs are appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要更新状态,它是一个数组;你非常接近,但你错过了括号:
You need to update the state which is an array; you were very close but you missed the brackets: