You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用RTK Query获取数据时调用reverse/sort报错:data is not iterable

问题:RTK Query返回的data调用reverse/sort时报错“data is not iterable”

我尝试对RTK Query返回的data调用reverse和sort方法,但每次执行reverse时都会报错:'data is not iterable'。

我的代码如下:

const {data, error, isLoading} = useGetTransactionsQuery()
const [modalState, setModalState] = useState<boolean>(false)

console.log(data.reverse())

我还尝试了以下写法,但均无效:

data.reverse()   
[...data].reverse()
Array.from(data).reverse(); 

其中使用Array.from(data).reverse()时,出现报错:

TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator)) at Function.from ()

内容的提问来源于stack exchange,提问作者JoyShaheb

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 09:10:39