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

在Supabase项目中使用RTK-Query报错:useGetStudentsQuery不是函数

问题排查与修复方案

以下是导致你遇到错误的几个关键问题及对应修复方法:

  • 导入路径错误
    你当前从@reduxjs/toolkit/query导入createApi,这个核心包不会生成React查询钩子(如useGetStudentsQuery)。必须从包含React集成的入口导入,修改导入行:

    import { createApi, fakeBaseQuery } from '@reduxjs/toolkit/query/react';
    
  • QueryFn返回格式不符合要求
    RTK-Query要求queryFn返回的对象必须包含data和error字段,同时需要正确解构Supabase的查询结果:

    queryFn: async () => {
      const { data: students, error } = await supabase
        .from('students')
        .select();
      return { data: students, error };
    }
    
  • 缺少Supabase实例导入(建议补充)
    确保代码中导入了项目中已配置好的Supabase实例,例如:

    import supabase from './your-supabase-config-path';
    
  • 确认Redux Store配置正确
    需要将RTK-Query的reducer和middleware添加到Redux store中,否则API无法正常工作,示例配置:

    import { configureStore } from '@reduxjs/toolkit';
    import { supabaseApi } from './supabaseApi';
    
    export const store = configureStore({
      reducer: {
        [supabaseApi.reducerPath]: supabaseApi.reducer,
      },
      middleware: (getDefaultMiddleware) =>
        getDefaultMiddleware().concat(supabaseApi.middleware),
    });
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.11 01:55:16