redux-toolkit icon indicating copy to clipboard operation
redux-toolkit copied to clipboard

Question: Is it ok for one slice to import another slice?

Open ChristophP opened this issue 1 year ago • 0 comments

I am having circular dependency problems in my root reducer which TypeScript complains about. It reads like

Circular definition of import alias `sliceB`

from a very simplified version of this code.

import sliceA from './slice-a';
import sliceB from './slice-b'; // this line gives a TS error
import { combineReducers } from '@reduxjs/toolkit';

const rootReducer = combineReducers({ sliceA, sliceB });

My root suspect is that in the codebase some slices import others in order to build selectors that aggregate data from different slices.

So my question is ...

... is it even ok to use selectors of one slice in another slice? If not, what is the best way to structure selectors that compose values from multiple slices?

Things I already tried

  • Googling Circular definition of import alias but I couldn't find any description of what exactly causes this error
  • Narrowing it down more but the codebase is quite large and I wasn't able to narrow it down a significant amount of effort

ChristophP avatar Oct 21 '24 14:10 ChristophP