DEV Community

Cover image for Single-File Components in React: Genius or Garbage?

Single-File Components in React: Genius or Garbage?

Samir Tahiri on July 11, 2025

Let’s start a fight (respectfully) 🥊 Recently, I came across a few React projects where the entire component was written in one file — logic, st...
Collapse
 
xwero profile image
david duymelinck •

Not a React dev. As I see it, a single file component in Vue or Svelte is closer to a web component.

Vue example

<script setup>
import { ref } from 'vue'

const count = ref(0)
</script>

<template>
  <button @click="count++">You clicked me {{ count }} times.</button>
</template>
Enter fullscreen mode Exit fullscreen mode

Here the separation between markup and logic is more visible.
In React it is a function with logic and markup.

Collapse
 
ivanjrmc profile image
Ivan Jeremic •

That's not how web-component definition looks like. Read on MDN on how to create and define custom elements and you will see.

Collapse
 
xwero profile image
david duymelinck •

I mentioned it is closer, not that it is a web-component definition. I added the link to MDN, that would be stupid if i didn't read it first.

Thread Thread
 
ivanjrmc profile image
Ivan Jeremic •

not even closer, makes no sense. A web-component is defined by doing. class MyComp extends HTMLElement

Thread Thread
 
xwero profile image
david duymelinck •

From MDM:

<template id="custom-paragraph">
  <style>
    p {
      color: white;
      background-color: #666666;
      padding: 5px;
    }
  </style>
  <p>My paragraph</p>
</template>
Enter fullscreen mode Exit fullscreen mode

Doesn't that look a lot like a Vue or Svelte component?

Thread Thread
 
ivanjrmc profile image
Ivan Jeremic • • Edited

That is not a web-component. Your link just shows an example of how the template tag can be used with web-components but this is not a web-component.

Collapse
 
dotallio profile image
Dotallio •

I've tried SFCs for quick MVPs and they do speed me up, but I always end up splitting things out as the project grows. Have you found a sweet spot where SFCs still work for big apps?

Collapse
 
samirtahiri profile image
Samir Tahiri •

Totally relate. SFCs are great for fast iteration and MVPs, but yeah — as the app grows, keeping everything in one file can feel cramped. I’ve found that the sweet spot is using SFCs for atomic components or isolated logic/UI pieces, and gradually splitting concerns (like store, styles, or templates) only when complexity demands it.

So basically: start simple, scale structure as needed. You?

Collapse
 
johanpiquet profile image
Johan PIQUET •

I'm a React dev and I love having one file per component and one CSS per component. It makes it much easier for CSS management.

Collapse
 
samirtahiri profile image
Samir Tahiri •

Yea 100%, i am with you here. It makes life easier and more structured fr

Collapse
 
9opsec profile image
9opsec •

This would be two files with the "Button.css" but I am ok with this for simple web sites.

Collapse
 
parag_nandy_roy profile image
Parag Nandy Roy •

SFCs feel like React’s version of a one-pot meal ..quick, satisfying, but maybe not for a five-course app 😄 Great convo starter..

Collapse
 
samirtahiri profile image
Samir Tahiri •

Yea 100%, thanks tho💪🏼

Collapse
 
parag_nandy_roy profile image
Parag Nandy Roy •

SFCs are like pineapple on pizza ...weirdly good in the right context

Collapse
 
dariomannu profile image
Dario Mannu •

If SFCs are like pineapple, custard, or strawberry-banana sandwiches on pizza, then yeah, you said everything about SFCs