createAsyncThunk and Next.js 13
Unanswered
Karakachan dog posted this in #help-forum
Karakachan dogOP
Introduction to the problem:
Where in the app/ folder to call dispatch for createAsyncThunk. For example, such a one:
And I need it throughout the system. Such a case: I go to app/home/invocies and I need user data for Navbar and for loading invoices.
For now, I think the best idea is to do it in layout.tsx, but it should be server-side without "use client", so I can't run distapcha there. And I don't see loading.tsx, so it's not the best way.
But also I can do it in any page.tsx, but there will be a lot of copy paste code.
And the last case when it needs data from useParam() like inv_id from app/home/invocies/[inv_id ]/edit
Where in the app/ folder to call dispatch for createAsyncThunk. For example, such a one:
export const getUserData = createAsyncThunk('user/getUserData', async (account_id: string) => {
const res = await axiosInstance.get(`/users/${account_id}`);
return res.data;
});And I need it throughout the system. Such a case: I go to app/home/invocies and I need user data for Navbar and for loading invoices.
For now, I think the best idea is to do it in layout.tsx, but it should be server-side without "use client", so I can't run distapcha there. And I don't see loading.tsx, so it's not the best way.
But also I can do it in any page.tsx, but there will be a lot of copy paste code.
And the last case when it needs data from useParam() like inv_id from app/home/invocies/[inv_id ]/edit