New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Redux store vs Redux API queries #4283
Comments
I don't know where you got that Instead of
and
do endpoints: builder => ({
getColorByTransmission: builder.query<BapImages | undefined, BapColorByTransmissionQueryArgs>({
- query: ({ url }) => ({ url }),
+ query: ({ transmissionId }) => ({ url: getUrl(`/qwe/${transmissionId}`) }),
}), and } = useGetColorByTransmissionQuery(
- { url: getUrl(`/qwe/${transmissionId}`), transmissionId },
+ { transmissionId },
{ skip: !transmissionId },
); On top of that, if your const bapApi = createApi({
reducerPath: 'bapApi',
- baseQuery: fetchBaseQuery(),
+ baseQuery: fetchBaseQuery({ baseUrl: process.env.BASE }) and endpoints: builder => ({
getColorByTransmission: builder.query<BapImages | undefined, BapColorByTransmissionQueryArgs>({
- query: ({ transmissionId }) => ({ url: getUrl(`/qwe/${transmissionId}`) }),
+ query: ({ transmissionId }) => ({ url: `/qwe/${transmissionId}` }),
}), which you can even more simplify for GET requests as endpoints: builder => ({
getColorByTransmission: builder.query<BapImages | undefined, BapColorByTransmissionQueryArgs>({
- query: ({ transmissionId }) => ({ url: `/qwe/${transmissionId}` }),
+ query: ({ transmissionId }) => `/qwe/${transmissionId}`,
}), (Generally, please watch this video course to understand Also, your
also makes me a bit afraid, because usually you should have one single api in your whole application. I'm gonna be honest: I know these pattern from some YouTube tutorials, and those tutorials are unfortunately not the best quality and show very weird (anti-)patterns. Maybe before you go deeper into your current discussion, could I motivate you somehow to spend some more time in our documentation? I'm sure when I can spot these problems that quickly, they're not gonna be the only ones. On the topic: We recommend against copying data from the query cache into your own reducers, because it's very common that it might get stale there and you might miss updates, and your data might stay around even when it is unused and should be cache-collected. I would recommend using the RTK Query cache, maybe with a layer of selectors on top - see deriving data with selectors. |
In our company, a dispute arose on the topic of how and where it is better to store and reuse data. Opinions were divided. Here I will give an example.
We have a queue of requests
The first request is to obtain vehicle data by its Transmission ID.
The second request is to get a gallery of links to pictures for the Interior and Exterior.
The third request is to get links to a gallery of 360 degree images for the Interior and Exterior.
One team's solution was this:
Api config
Main hook to chain requests
Reducer and Selectors
Well, naturally, the component called the Hook and received data from the reducer through selectors.
The second command did this:
Main hook to chain requests
Api layout
And as you can see, the API contains
transformResponse
for each request, I will not present them here, I think the logic is clear.Summary
It turns out that one team created a data warehouse, formats everything there as it should, saves it, and takes data from there.
The second team abandoned the Reducer and each time retrieves the transformed data from API queries.
If you compare, there are pros and cons in both options. I would like to know the community’s opinion on what, in your opinion, is the correct way to store data and why?
Additionally, if there are other options, I will be glad to communicate in the comments.
Thank you
The text was updated successfully, but these errors were encountered: