Closed
Description
I'm quite new to redux-toolkit
and have no idea how to solve this kind of circular dependency (code is heavily cut):
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
interface Organization {
name: string;
}
const fetchSingleOrganization = createAsyncThunk<Organization, string, { state: RootState }>(
"organizations/fetch-single",
async (id, { getState }) => {
// fetch code
},
);
const organizationsSlice = createSlice({
name: "organizations",
initialState: null,
reducers: {},
extraReducers: (builder) =>
builder.addCase(fetchSingleOrganization.fulfilled, () => {
// upsert code
}),
});
const store = configureStore({
reducer: {
organizations: organizationsSlice.reducer,
},
});
type RootState = ReturnType<typeof store.getState>;
This results in a Type alias 'RootState' circularly references itself.ts (2456)
error. I need a full state in a fetchSingleOrganization
function, not just this slice. I can see the problem, but don't know how to fix it. It would probably resolved fine, if there was an option to add extraReducers
afterwards, but I can't see one. What is a correct approach here?
Metadata
Metadata
Assignees
Labels
No labels