Search code examples
reduxreact-reduxredux-toolkitrtk-query

RTK Query: undefined extraOptions inside prepareHeaders


I set extraOptions in my endpoint like so :

const myApi = api.injectEndpoints({
  endpoints: builder => ({
      changePassowrd: builder.mutation({
          query: (data) => ({
              url: `${Config.BASE_URL}/users/${data.userId}`,
              method: 'PATCH',
              body: data,
          }),
          extraOptions: () => ({
            myOption: 'Test Option',
          }),
      }),
  })
})

And I try to read extraOptions in prepareHeaders like so:

const baseQuery = fetchBaseQuery({
  baseUrl: Config.BASE_URL,
  prepareHeaders: (headers, {getState, extra}) => {

    console.log('Extra Stuff', extra); // undefined

    return headers;
  },
});

But I'm always getting undefined in the console after triggering the mutation, why is that? Am I using it wrong?


Solution

  • That's redux-thunk's extra, not the endpoint's extraOptions. It seems like fetchBaseQuery generally does not make use of extraOption - a pull request integrating that where necessary is highly welcome.