#Best practise for fetching data in nested dynamic routes
1 messages · Page 1 of 1 (latest)
🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord
🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize
✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)
abstract the code of fetching the data
didn't get it
@ornate matrix it would help if you showed your existing code
For example I have to do this for every single route inside dynamic route
const branchPromise = getBranch(bid);
const employeesPromise = getEmployees(query, validPage, validPerPage);
const [branch, employees] = await Promise.all([
branchPromise,
employeesPromise,
]);
I have to check for branch if it exists or not then get data related to this route and if this route has dynamic route inside it like
/branches/[bid]/employees/[empid]
it gets worse
All of routes inside /branches/[bid] depends on branch data
@fossil flume Here's an example