Skip to main content

# useInjectQuery()

    function useInjectQuery(config: {
      middleware: Middleware;
      reducer: Reducer<any, AnyAction>;
      reducerPath: string;
    }): void;

React hook to dynamically inject RTK Query API slice into the Redux store. Registers the reducer and middleware for the API slice at runtime.

## Parameters​

### config​

Query injection configuration

#### middleware​

`Middleware`

The RTK Query middleware

#### reducer​

`Reducer`<`any`, `AnyAction`>

The RTK Query reducer

#### reducerPath​

`string`

Path where the reducer will be mounted in the store

## Returns​

`void`

## Example​

    import { createApi } from '@reduxjs/toolkit/query/react';
    import { useInjectQuery } from '@elliemae/pui-app-sdk';

    const usersApi = createApi({
      reducerPath: 'usersApi',
      baseQuery: sdkBaseQuery(),
      endpoints: (builder) => ({...})
    });

    function MyComponent() {
      useInjectQuery({
        reducerPath: usersApi.reducerPath,
        reducer: usersApi.reducer,
        middleware: usersApi.middleware
      });

      return <div>...</div>;
    }