Next.js Discord

Discord Forum

Where should get the Data?

Answered
West African Lion posted this in #help-forum
Open in Discord
Avatar
West African LionOP
I have a products route, and I have a form to add the product, where's should I call the getCategories function to get all the categories for the product? should I create a categories context and make it available for the product layout and its children? or is there a better practice?
Answered by B33fb0n3
no, some people like it that way, some the other way. Normally your audience is a group of people that like the same way. So when you know your audicene (and the way) you can easily provide the best way for them
View full answer

7 Replies

Avatar
you can do it however you like (or whats best for your user). Fetch them when he enteres the product page.
Fetch them when he want to select a category
Fetch them after a specific delay after the user opened the product page
Fetch them at a specific point
...

You decide when you want to fetch what to provide the best experience to your user
Avatar
West African LionOP
so would creating a category context and making it available for the page layout's children be good? because m not entirely sure what's the best choice for the best user experience .. and m definitely sure there better ways than others
Avatar
do what your user likes. I am not familiar with your audience, but you are. So take a look on how they would operate and add it like that
Avatar
West African LionOP
interesting .. so there's no certain opinionated way of doing it?
Avatar
no, some people like it that way, some the other way. Normally your audience is a group of people that like the same way. So when you know your audicene (and the way) you can easily provide the best way for them
Answer
Avatar
West African LionOP
this is more of a personal project .. to cement my knowledge of nextjs and interacting with databases etc .. thank you for you feedback .. I appreciate it
Avatar
sure thing