I want to fetch data from the products table that I made in my supabase project also I want to use Redux toolkit for state management, I also tried this code in apiSlice.js but it just get data for one time after render and then the data will be undefined.
Is there any way to fetchdata from supabase with reduxThunk or extraReducer?
Can anyone help me??
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
import { supabase } from '../../supabase/client';
export const apiSlice = createApi({
reducerPath: 'api',
baseQuery: fetchBaseQuery({ baseUrl: '/' }),
endpoints: (builder) => ({
getItems: builder.query({
queryFn: async () => {
const response = await supabase.from('products').select();
if (response.error) {
return { error: response.error };
}
return { data: response.data };
},
}),
}),
});
export const { useGetItemsQuery } = apiSlice;
New contributor
user25904704 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.