Skip to content
Centrion
Go back

Keep React Components Small

Keep React Components Small

In React projects, complexity usually doesn’t arrive all at once. A small component gets a couple of conditionals, then data fetching, then a growing form state. After a while, the file ends up carrying the screen, the business rule, and the side effects all together.

Separate UI from Logic

If a component is both preparing data and drawing UI, it has two responsibilities. Splitting the data part into a hook and the UI into smaller components is usually enough.

function PostsPage() {
  const { posts, loading } = usePosts();

  if (loading) return <LoadingState />;
  return <PostList posts={posts} />;
}

Naming Defines Boundaries

Names like PostList, PostCard, PostMeta already communicate how much work a component should do. A good name is a good boundary.

Conclusion

Small components matter not just for reuse, but for making the code easier to think about. Readable UI code is the quiet foundation of good product development.


Share this post:

Previous Post
Clarity in API Design
Next Post
A Fast Blog Architecture with Astro

Comments

Sign in with GitHub to post a comment.

Comments

Loading comments...