Gotta resolve any issues that get reported during the alpha, and apply any final changes left over from the old repo.
Can't wait to test RTK-Query in my new projects!
Minor note, in the changelog the import path is import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/react' when it looks like it should be import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'.
@mgcrea Thanks, updated it.
Yeah, we need to go through and add visibility attributes to all types so we stop getting extraction warnings.
Running list of merged PRs since alpha.2 for reference:
copyWithStructuralSharingselectFromResult usageMiddleware<any> from casting dispatch to anyjust some minor tweaks :laughing:
Still missing on that list:
merge (or mergeWithLastResult option to endpoints)merge, that's only gonna be useful in a "streaming" context)And then I think I'm actually really out of ideas on what else to add.
First of all, excellent functionalities for RTK query, start refactoring our codes by adopting alpha.2, can't wait the official release.
A quick question ,Is there any way to change baseUrl after calling createApi?
In our app we allow user to change the server address which is stored in the redux state, and will be used in following REST API call. It seems that baseUrl for RTKQ can't be modified after initialization.
Thanks!
@bravew : phryneas mentioned on Discord that this could be done by wrapping baseQuery, as that have access to getState. I had a similiar usecase, where i wanted to add a projectId to the url. Here is an (untested, but hopefully working) example:
import { fetchBaseQuery } from '@rtk-incubator/rtk-query';
import { createApi } from '@rtk-incubator/rtk-query/react';
const baseQuery = fetchBaseQuery({
baseUrl: 'http://localhost:8000/'
});
const wrappedBaseQuery = (
...[args, api, extraOptions]: Parameters<typeof baseQuery>
) => {
const partialUrl = typeof (args) === 'string' ? args : args.url
const projectId = (api.getState() as any).auth.projectId // circular reference if as RootState
const url = `project/${projectId}/${partialUrl}`
const newArgs = typeof (args) === 'string' ? url : { ...args, url }
return baseQuery(newArgs, api, extraOptions)
}
export const api = createApi({
baseQuery: wrappedBaseQuery,
...
(Note that I haven't updated to next RTK, so i'm using the old imports)
@StefanBRas , Thanks a lot , your code provides the last piece of our puzzle.
@Shrugsy that snippet seems worth adding to "Customizing Queries"
:rocket:
Most helpful comment
@Shrugsy that snippet seems worth adding to "Customizing Queries"