

You can divide your main store into smaller individual stores to achieve modularity. Let's implement fold (Your implementation may vary and be more performant. Slices Pattern Slicing the store into smaller stores Your store can become bigger and bigger and tougher to maintain as you add more features. How about if we had the ability to fold ( reduce) a Map? That seems like something that would be useful here. Let's build out an implementation of this interface taking into account some ideas we might have from functional programming. What about non-string keys? What about something like functions? const randomFunction = () => 'I am very random' Ĭonst result = between('one-string', randomFunction, themap) The generated slice reducer and the middleware both. It also automatically generates a custom Redux middleware that manages subscription counts and cache lifetimes. Let's first define how we'd like to use our function: const result = between('one-string', 'another-string', themap) Internally, createApi will call the Redux Toolkit createSlice API to generate a slice reducer and corresponding action creators with the appropriate logic for caching fetched data. This answer is a bit lengthy because I want to express the journey so here goes. I'd also like to provide something for those who arrive at this question looking for a way to slice their Map based on arbitrary keys, not just ordered sequences of integers. I really like answer and I think it's rightly the accepted answer for this question.
