nter: { value: 2 } }), // 2  
    )  
    

caution

The ` Proxy ` retrieves a reducer's initial state by calling it with a
randomly generated action type - don't try to handle this as a special case
inside your reducer.

####  Nested combined reducer  ​

The wrapped selector expects to use the state returned by the combined reducer
as its first argument.

If the combined reducer is nested further inside the store state, pass a `
selectState ` callback as the second argument to ` selector ` :

    
    
    interface RootState {  
      innerCombined: ReturnType<typeof combinedReducer>  
    }  
      
    const selectCounterValue = withCounter.selector(  
      (combinedState) => combinedState.counter.value,  
      (rootState: RootState) => rootState.innerCombined,  
    )  
      
    console.log(  
      selectCounterValue({  
        innerCombined: {},  
      }), // 0  
      selectCounterValue({  
        innerCombined: {  
          counter: {  
            value: 2,  
          },  
        },  
      }), // 2  
    )  
    

####  ` original ` ​

Similar to [ Immer usage ](/usage/immer-reducers#debugging-and-inspecting-
drafted-state) , an ` original ` function is provided to retrieve the original
state value provided to the ` Proxy ` .

This is mainly useful for debugging/inspecting, as ` Proxy ` instances tend to
be displayed in a format that's hard to read.

The function is attached as a method on the ` selector ` function:

    
    
    const wrappedSelectCounterValue = withCounter.selector((rootState) => {  
      console.log(withCounter.selector.original(rootState))  
      return rootState.counter.value  
    })  
    

##  Slice integration  ​

###  ` injectInto ` ​

Slice instances returned by [ ` createSlice ` ](/api/createSlice) have an
attached ` injectInto ` method, which receive an injectable reducer from `
combineSlices ` and returns an "injected" version of that slice.

    
    
    const injectedCounterSlice = counterSlice.injectInto(rootReducer)  
    

An optional configuration object can be passed. This follows  ` inject ` 's
options with an additional ` reducerPath ` field, for injecting the slice
under a path other than its current ` reducerPath ` property.

    
    
    const aCounterSlice = counterSlice.injectInto(rootReducer, {  
      reducerPath: 'aCounter',  
    })  
    

###  ` selectors ` / ` getSelectors ` ​

Similar to  ` selector ` , the selectors from an "injected" slice instance
behave slightly differently.

If the slice state is undefined in the store state passed, the selector will
instead be called with the slice's initial state.

` selectors ` will also reflect the change in ` reducerPath ` if one was made
during injection.

    
    
    console.log(  
      injectedCounterSlice.selectors.selectValue({}), // 0  
      injectedCounterSlice.selectors.selectValue({ counter: { value: 2 } }), // 2  
      aCounterSlice.selectors.selectValue({ aCounter: { value: 2 } }), // 2  
    )  
    

Last updated  on ** Feb 11, 2024  **

[ Previous  createEntityAdapter  ](/api/createEntityAdapter) [ Next
createSelector  ](/api/createSelector)

  * Overview 
  * Parameters 
  * Return Value 
    * ` withLazyLoadedSlices `
    * ` inject `
    * ` selector `
  * Slice integration 
    * ` injectInto `
    * ` selectors ` / ` getSelectors `

Docs

  * [ Getting Started ](/introduction/getting-started)
  * [ Tutorials ](/tutorials/overview)
  * [ Usage Guide ](/usage/usage-guide)
  * [ API Reference ](/api/configureStore)
  * [ RTK Query ](/rtk-query/overview)

Community

  * [ Stack Overflow  ](http://stackoverflow.com/questions/tagged/redux)
  * [ Discord  ](https://discord.gg/0ZcbPKXt5bZ6au5t)

More

  * [ GitHub  ](https://www.github.com/reduxjs/redux-toolkit)
  * [ ![Deploys by Netlify](https://www.netlify.com/img/global/badges/netlify-light.svg) ](https://www.netlify.com)

![Redux Logo](/img/redux_white.svg) ![Redux Logo](/img/redux_white.svg)

Copyright © 2015–2024 Dan Abramov and the