Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

220
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda