
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...
For further actions, you may consider blocking this person and/or reporting abuse
Not a React dev. As I see it, a single file component in Vue or Svelte is closer to a web component.
Vue example
Here the separation between markup and logic is more visible.
In React it is a function with logic and markup.
That's not how web-component definition looks like. Read on MDN on how to create and define custom elements and you will see.
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.
not even closer, makes no sense. A web-component is defined by doing.
class MyComp extends HTMLElement
From MDM:
Doesn't that look a lot like a Vue or Svelte component?
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.
If a template is used by a web component, how is that not web component syntax?
What you think a web component is,
class MyComp extends HTMLElement
, is a custom element. This also can be created by using<my-comp></my-comp>
, .Web component is not a strict definition. It is a set of features in HTML, CSS and javascript that work together. And HTML is the most import part because it is the base.
This is a declarative web component.
Javascript is not a requirement.
Thanks David, great point!
You're right – Vue and Svelte with SFCs definitely highlight that clear separation of markup and logic. In React, the JSX + hooks combo can feel more “blended” since everything lives in one function. That’s exactly what I was touching on in the post – how different frameworks structure and think about components.
Both approaches have pros depending on the mindset and team habits. Appreciate the Vue example!
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?
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?
SFCs feel like React’s version of a one-pot meal ..quick, satisfying, but maybe not for a five-course app 😄 Great convo starter..
Yea 100%, thanks tho💪🏼
This would be two files with the "Button.css" but I am ok with this for simple web sites.
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.
Yea 100%, i am with you here. It makes life easier and more structured fr
SFCs are like pineapple on pizza ...weirdly good in the right context
If SFCs are like pineapple, custard, or strawberry-banana sandwiches on pizza, then yeah, you said everything about SFCs