Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

223
Views
Fetching data from Supabase in Redux, gives me a Promise that I can't resolve

EDIT : I made a codesandbox, it's probably much easier that way : https://codesandbox.io/s/serverless-cloud-98fil?file=/pages/index.js

I'm trying to create a Redux slice with an initial value containing all the data from a Supabase table called "residents". My slice is looking like this :

import { createSlice } from "@reduxjs/toolkit";
import { supabase } from "utils/supabaseClient";

async function setInitialValue() {
    const { data, error } = await supabase.from("residents").select();
    return data;
}

export const residentsSlice = createSlice({
    name: "residents",
    initialState: {
        value: setInitialValue(),
    },
    ...
});

export default residentsSlice.reducer;

Then I include this into my store :

import { configureStore } from "@reduxjs/toolkit";
import residentsReducer from "stores/residents";

export default configureStore({
    reducer: {
        residents: residentsReducer,
    },
});

And finally I try to use it on my homepage :

import { useState, useEffect } from "react";
import { supabase } from "utils/supabaseClient";
import { useSelector, useDispatch } from "react-redux";


export default function Home() {
    const [session, setSession] = useState(null);

    const residents = useSelector((state) => {
        return state.residents.value;
    });
    ...
}

If I try console-logging the data object from the setInitialValue() function, it gives me an Array of 10 items (exactly what I expect). But if I log the residents constant from my homepage, then it gives me a Promise with state:fulfilled, but I can't use it.

My guess is that the log on the homepage is happening before the promise gets resolved. What could I do in this case ? I've always had a hard time understanding promises.

Thank you for your help !

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!