Next.js Discord

Discord Forum

Help with structuring blog code

Unanswered
Spruce Grouse posted this in #help-forum
Open in Discord
Spruce GrouseOP
Hey
I'm building a blog website with nextjs, tailwind and radix and I'm wandering how the code will be structured, i have rich homepage and the page file have 300 lines.
is that okey according to nextjs standers??
i have thought about taking out some of the chunks of the code into separate component but these component are not used in any other page, so do i make separate component for the each section i the homepage? or leave it as it is?

3 Replies

Cinnamon Teal
The code doesn't necessarily need to be reused in multiple components for you to break it up a bit. It's up to you. For example, if you somehow ended up with a big component, for readability you could break it up a bit. That's not a bad thing.

Now, when you say 300 lines of code is this component logic and UI? Or is this text content for your blog? If it's text content you still could break it up, but at that point I would switch to something like MDX to write the blog content rather than working with .tsx files.

With MDX you can write markdown content as well as React components, in the same files. You can write your text in markdown and import any interactive components you have into the same file.
Cinnamon Teal
Ah ok. In that case just leave it as it is or break into couple of components. It's not an issue. If all the sections in the homepage are in one file/component, you can break it down to different sections that are visually present in the UI. I wouldn't break things into too many components, that also gets annoying.