I've being trying populate my redux store with data that comes from my mongo-db realm database.Whenever I run the function below it will execute fine but the problem is data will be delayed and ends up not reaching my redux store.
My thunk function:
export const addItemsTest = createAsyncThunk("addItems", async (config: any) => { try { return await Realm.open(config).then(async (projectRealm) => { let syncItems = await projectRealm.objects("Item"); await syncItems.addListener((x, changes) => { x.map(async (b) => { console.log(b); return b; }); }); }); } catch (error) { console.log(error); throw error; } });
and my redux reducer:
extraReducers: (builder) => { builder.addCase(addItemsTest.fulfilled, (state, { payload }: any) => { try { console.log("from add Items"); console.log(payload); state.push(payload); } catch (error) { console.log(error) } }); }
Expected Results:My redux store should have these data once addItemsTest
return something:
[{itemCode: 1,itemDescription: 'Soccer Ball',itemPrice: '35',partition: 'partitionValue',},{itemCode: 2,itemDescription: 'Base Ball',itemPrice: '60',partition: 'partitionValue',}]