<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: EliezerKibet</title>
    <description>The latest articles on DEV Community by EliezerKibet (@eliezerkibet).</description>
    <link>https://dev.to/eliezerkibet</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3961150%2Fb4e03329-69d3-49e3-8f94-d55da14215e6.jpeg</url>
      <title>DEV Community: EliezerKibet</title>
      <link>https://dev.to/eliezerkibet</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/eliezerkibet"/>
    <language>en</language>
    <item>
      <title>How to Structure Reusable Components in a Next.js Project</title>
      <dc:creator>EliezerKibet</dc:creator>
      <pubDate>Sun, 31 May 2026 12:24:54 +0000</pubDate>
      <link>https://dev.to/eliezerkibet/how-to-structure-reusable-components-in-a-nextjs-project-5535</link>
      <guid>https://dev.to/eliezerkibet/how-to-structure-reusable-components-in-a-nextjs-project-5535</guid>
      <description>&lt;p&gt;How to Structure Reusable Components in a Next.js Project&lt;br&gt;
One habit separates Next.js codebases that stay clean from ones that become a nightmare to maintain — thinking in reusable components from day one. Here is the structure and rules I use on every project.&lt;/p&gt;

&lt;p&gt;Why Component Structure Matters&lt;br&gt;
Most developers start a Next.js project by building pages. Then they copy a button here, a card there. Six weeks in, the same UI element exists in 11 different files — each slightly different. Change one, the others stay broken.&lt;/p&gt;

&lt;p&gt;The fix isn't discipline. It's structure. When there's a clear place for everything, the right decision becomes the obvious decision.&lt;/p&gt;

&lt;p&gt;Three Layers — Everything Fits Somewhere&lt;br&gt;
components/&lt;br&gt;
  ui/          ← no business logic, pure display&lt;br&gt;
    Button.tsx&lt;br&gt;
    Card.tsx&lt;br&gt;
    Badge.tsx&lt;br&gt;
    Input.tsx&lt;/p&gt;

&lt;p&gt;layout/      ← structure shared across pages&lt;br&gt;
    Navbar.tsx&lt;br&gt;
    Footer.tsx&lt;br&gt;
    PageWrapper.tsx&lt;/p&gt;

&lt;p&gt;features/    ← specific to one domain&lt;br&gt;
    blog/&lt;br&gt;
      BlogCard.tsx&lt;br&gt;
      BlogList.tsx&lt;br&gt;
    projects/&lt;br&gt;
      ProjectCard.tsx&lt;br&gt;
      ProjectGrid.tsx&lt;br&gt;
ui/ — components that know nothing about your application. They receive data via props and render it. No API calls, no business logic, no assumptions about where they'll be used.&lt;/p&gt;

&lt;p&gt;layout/ — components that define the structure of a page. These appear on every page or most pages. The Navbar doesn't know what page it's on. The Footer doesn't know what content surrounds it.&lt;/p&gt;

&lt;p&gt;features/ — components tied to a specific domain of your application. A BlogCard knows about blog posts. A ProjectCard knows about projects. They live close to the feature they belong to.&lt;/p&gt;

&lt;p&gt;The One Rule&lt;br&gt;
If a component appears in more than one place, it belongs in ui/.&lt;/p&gt;

&lt;p&gt;That's it. Apply that rule consistently and the folder structure stays clean without active effort.&lt;/p&gt;

&lt;p&gt;What a Good Reusable Component Looks Like&lt;br&gt;
A good reusable component has one job. The moment you find yourself adding props to control five different behaviours, the component is doing too much.&lt;/p&gt;

&lt;p&gt;// ❌ Doing too much — too many responsibilities in one component&lt;br&gt;

  project={project}&lt;br&gt;
  showContact&lt;br&gt;
  showBadge&lt;br&gt;
  openModal&lt;br&gt;
  variant="featured"&lt;br&gt;
/&amp;gt;&lt;/p&gt;

&lt;p&gt;// ✓ One clear responsibility&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Split it when a component starts accumulating conditional props. Each piece is easier to test, easier to update, and easier to reuse independently.&lt;/p&gt;

&lt;p&gt;Use children and className to Extend Without Coupling&lt;br&gt;
The most flexible pattern for UI components is accepting children and an optional className. This lets the component be extended at the call site without changing the component itself.&lt;/p&gt;

&lt;p&gt;interface CardProps {&lt;br&gt;
  children: React.ReactNode;&lt;br&gt;
  className?: string;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;export function Card({ children, className }: CardProps) {&lt;br&gt;
  return (&lt;br&gt;
    &lt;/p&gt;
&lt;br&gt;
      {children}&lt;br&gt;
    &lt;br&gt;
  );&lt;br&gt;
}&lt;br&gt;
Now Card works everywhere. Blog post previews. Project tiles. Pricing sections. Testimonial blocks. You style it at the call site using className, not by adding props inside the component.

&lt;p&gt;// Blog post&lt;br&gt;
&lt;br&gt;
  &lt;br&gt;
&lt;/p&gt;

&lt;p&gt;// Pricing tier&lt;br&gt;
&lt;br&gt;
  &lt;br&gt;
&lt;br&gt;
One component. Two completely different use cases. No new props required.&lt;/p&gt;

&lt;p&gt;Co-locate Types With Components&lt;br&gt;
Keep the TypeScript interface for a component's props in the same file as the component. Don't create a separate types/ folder for component props — it's unnecessary indirection.&lt;/p&gt;

&lt;p&gt;// BlogCard.tsx&lt;br&gt;
interface BlogCardProps {&lt;br&gt;
  title: string;&lt;br&gt;
  excerpt: string;&lt;br&gt;
  date: string;&lt;br&gt;
  slug: string;&lt;br&gt;
  tags: string[];&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;export function BlogCard({ title, excerpt, date, slug, tags }: BlogCardProps) {&lt;br&gt;
  // ...&lt;br&gt;
}&lt;br&gt;
The type lives where it's used. When you update the component, the type is right there. No switching files.&lt;/p&gt;

&lt;p&gt;When to Create a New Component&lt;br&gt;
A useful heuristic: if you're about to copy and paste JSX, stop and ask whether it should be a component instead.&lt;/p&gt;

&lt;p&gt;The answer is yes if:&lt;/p&gt;

&lt;p&gt;The same JSX will appear in more than one place&lt;br&gt;
The block of JSX has a clear, nameable responsibility&lt;br&gt;
You want to test it in isolation&lt;br&gt;
The answer is no if:&lt;/p&gt;

&lt;p&gt;The JSX only appears once and is unlikely to be reused&lt;br&gt;
Extracting it would make the code harder to read, not easier&lt;br&gt;
It would need so many props to be generic that it's more complex than just writing it inline&lt;br&gt;
The Payoff&lt;br&gt;
None of this feels significant on day one. The folder structure looks like overhead. The discipline of keeping components single-responsibility feels like extra work.&lt;/p&gt;

&lt;p&gt;Day 60 is when it pays off.&lt;/p&gt;

&lt;p&gt;You need to update a button style. In a well-structured project, you change Button.tsx once. It updates everywhere. In a project without structure, you spend three hours finding every place a button was copy-pasted and hoping you didn't miss one.&lt;/p&gt;

&lt;p&gt;You need to add a loading state to a card. In a well-structured project, you add it to Card.tsx and every card in the application gets it. In an unstructured project, you add it to the three different inline card implementations and forget the fourth.&lt;/p&gt;

&lt;p&gt;Build components like you're building a library — even when you're the only one using it. Future you, six months from now, will thank you.&lt;/p&gt;

&lt;p&gt;If you're building a Next.js application and want to talk through the architecture before you start, get in touch. Getting the structure right at the start is far cheaper than refactoring it later.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>nextjs</category>
      <category>react</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
