title: RTK Query get state from another slice using getState()
body: <p>I just started on redux yesterday and after reading up on the different libraries, I decided to use the slice route from RTK.</p>
  <p>For my async, instead of using createAsyncThunk, I decided to use RTK query and I have a question on the right way to access state from another slice.</p>
  <p>slice1 contains some user data for example:</p>
  <pre><code>export const initialState: IUserState = {
     name: 'example',
     id: null,
  };
  </code></pre>
  <p>and in my slice2, I have a function that wants to do something like <strong>getSomethingByUserId(id)</strong> and my current implementation:</p>
  <pre><code>interface IApiResponse {
    success: true;
    result: IGotSomethingData[];
  }
  
  const getsomethingSlice: any = createApi({
    reducerPath: 'api',
    baseQuery: fetchBaseQuery({
      baseUrl: 'https://someapibase',
    }),
    endpoints(builder) {
      return {
        fetchAccountAssetsById: builder.query&lt;IApiResponse, null&gt;({
          query() {
            console.log('store can be called here', store.getState().user.id);
            return `/apipath?id=${store.getState().user.id}`;
          },
        }),
      };
    },
  });
  
  export default getsomethingSlice;
  export const { useFetchAccountAssetsByIdQuery } = getsomethingSlice;
  </code></pre>
  <p>As I read somewhere that markerikson mentioned it's not good practice to import the store but to use getState in thunk, I took a look around and see in the <a href="https://rtk-query-docs.netlify.app/concepts/queries" rel="noreferrer">documentations</a> that there is getState for query which exist in the onStart unlike thunk which you can access it from it's second parameter.</p>
  <p>Do anyone have a onStart implementation for this? Or is importing store acceptable for this?</p>