If I want to maintain a global state without slices, do I still have to use the createSlice fn? #5184
Replies: 1 comment 5 replies
-
|
I'm kind of confused on the question :)
But, we have always taught users to break their Redux root state down into smaller pieces ("slices") based on the types of data.
It's not strictly required. But it's the same principle as any other code you write. You break down larger functions into smaller functions to make them easier to understand and maintain. So, the standard pattern is one Again, if you want to do something different you can. This is perfectly legal: const rootStateReducer = createSlice({name: "doesntMatterHere"})
const store = configureStore({reducer: rootStateReducer})but now your root reducer is having to keep track of all the state nesting itself. Beyond that: a Redux store is a "global source of truth" with "all the state in the same place". Slices are just a way to split the root reducer up into smaller functions. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello - old Redux/Re-frame user here, still coming back here with a fun question ...
I, personally, prefer a single source of truth, to put all states in one global place.
Yet, to initialise the global state, I would have to use the
createSlicefunction, which feels misleading.Because a global state is not a slice. It's like saying, a universe consists of multiple universes? 😅
What I am after, is to initialise the global state based on React props of the root component.
Beta Was this translation helpful? Give feedback.
All reactions