Introduction: Taming the Next.js Jungle
Hey there, code wranglers and Next.js enthusiasts! ๐ Are you feeling like Indiana Jones, hacking...
For further actions, you may consider blocking this person and/or reporting abuse
Great written boy. I am Senior Software Engineer and I appreciate this structure. One minor thing I will suggest to improve, the components is a different thing and forms is a different.
For forms and big layouts, which are route related (means which are for a specific page) they should kept in modules directory..
And only reusable components should kept in components directory. That it. I just wanted to see how others structure this and what are you teaching to other.
With that minor improvement, I suggest all the juniors to follow this structure!!!
Where are components styles? I have a structure
components/
|__ component-name/
|_____ component-name.module.scss
|_____ index.tsx
|__ index.ts
in index.ts:
export * from โ./component-nameโ
so after that I can import components like
import { ComponentName } from โ@/componentsโ;
Barrel exports are easier to make but can increase your code import size. Also, they can leak client component code into server components and vice versa.
Thanks a lot for this. Never knew and never met explanations for it
I do it the same way! ๐
Nice article, but I think you should update the
API Routes for the Win
section @vyan, because that's not an API Route from Next.js 13+ :) It is more like:Thanks!
Regarding to auth, we have an opposite structure - keep most pages in
(authorized)
dir and onlylogin/register
on the root level. This is because for all authorized pages we have a header in layout, but it is not shown on login/register pages:Could you advice how can we achieve the same with
(auth)
dir?Next is a very clean language.
NextJS has JS in the name because is Javascript. And Javascript is a language.
Why bother with a Microsoft (evil) tool as Typescript if we have JSDoc?
hey!!, this is exactly my structure
Cool
Where would you likely put server action files? Would it be inside its own folder within the root folder or inside the
lib
?Great article! I did notice that you omitted an โactionsโ folder under lib, but this is probably because you are using /api as a backend instead of SAs. Additionally, you have reference components that are using client side hooks but you didnโt annotate the file like so: โuse clientโ
All these folders do they have extra price of coding within them?
If yes how do u write those and embed them on ur Next.js screen.....
Secondly can I use vs.code to work on a next.js app?
Can I also write them in pseudocode?
"In the constantly changing field of web development.", the pursuit of speed, efficiency, and simplicity is ceaseless, much like the advances in AI-powered tools explored in our GitHub Copilot vs Chatbot article. Next, js 14, Vercel's latest innovation, has arrived to redefine the way we construct web applications. Equipped with an array of enhancements, including the groundbreaking TurboPack, robust Server Actions, and the eagerly anticipated Partial Pre-Rendering, Next js 14 is set to transform your web development experience, Read more at webzeto.com
Thank for sharing
My Pleasure!
Hi I need nextjs with swagger-autogen 3.0
It's works but not able to get dynamic routes each endpoints of the top we need to add some swagger schema why
I don't want like to add schema like swagger 2.0
If any one solve it please add a blog and tag @ashok2406
oh no, is this the end๏ผ
but i still give a sponsor
For What ?
Useful thanks
Thanks very insightful. Do you have an example in Github?
Cool
Fantastic article.
Great
And another tip or maybe personal preference: use named exports for your components. This makes sense for code intellisense.
Nice! This is close to how I structure my Next.js apps.
Wow I woul not wait to use it lately thanks for this awesome advice
Where/how would you add tests/mocks to the structure?
@vyan any GitHub link available? so that I can explore the structure more?
I love to learn from you,after seeing this article
Such a good content. Mine is also matching but learned a few things from you.
Nice
thanks for sharing!
Cool
Thank for sharing
Hey, what are the pros of dynamic importe i.e code splitting?
Imagine you have a
<Dialog>
component that heavily relies on JavaScript. If this component is loaded with the initial page render, it increases the initial bundle size unnecessarily, especially if the user never opens the dialog. With dynamic imports, such as in Next.js 13+ usingconst Dialog = dynamic(() => import('../components/Dialog'))
, you only load the component when it's needed. This means the JavaScript for the<Dialog>
component is only loaded when the button to open it is clicked. Hope this helps. You can also take a look at the reference in the Next.js docs.I love this
Nice
Good post!
Thanks!
Very useful post keep sharing more like this ๐๐
Yes, I will share more!
Useful article, thanks
Tq!
๐๐๐๐๐
Codefolder best coding platform
Thank you found this very helpful
Am planning to delve into next.js and I must say this article has really convinced me and given me great perspective about the framework.
Thanks
Berfact โ๏ธ
Keep going explain more
Thank you for the knowledge.
I will add it to my project development