Eh, I understand what you're saying, but I think that approach is wrong. For context, I've been writing React for 5 years, and web components for 2. When dealing with web components, you need to break your "react way" of thinking. React gives you a lot, and abstracts a lot, but does most things in a non-standard way. The whole benefit of web components and a 3kb library like lit-element is that there isn't any of that. It's all just web standards.
For example, mixins are not old school. They are for React, but if you're using React 17, you're writing React code. Just because you don't need to write a mixin anymore doesn't mean mixins aren't useful and aren't the recommended way of dealing with browser native classes. Just like events. You normally would never write an element.addEventListener in React except for very specific cases. That doesn't mean that addEventListener is outdated, that's literally the way you deal with events in the browser.
And in reality, I've learned more and more about webcomponents in general, as well as lit-element over the past 2 years, and if I had to boil down my learnings it would be that a lot of stuff React does isn't the "right" way of doing it. It's just "a" way. Just like how Vue and Angular have some non web standard ways of doing things. The right answer to a problem in web components is almost never to port react stuff directly over.
For example, the webcomponent project I work on is embedded in other applications, so it needs to be small. It's a huge, complicated application and I've been able to solve every problem I have with zero external dependencies except for lit-element, just by diving more deeply into the lit-element source code, and taking a look at more advanced webcomponent libraries to see how they do more advanced stuff.
It's really just a slight change in thinking. But for the record, yes I definitely agree with you that more advanced composition can be difficult, but it's possible to achieve just about anything since you're literally just manipulating the DOM with javascript.
Also for people that are really stuck in the React way of thinking, there are actually numerous webcomponent libraries that allows you to pretty much write code identical to React, that outputs a web component.
View all comments
Show parent comment
1
u/Yodiddlyyo Dec 06 '20
Eh, I understand what you're saying, but I think that approach is wrong. For context, I've been writing React for 5 years, and web components for 2. When dealing with web components, you need to break your "react way" of thinking. React gives you a lot, and abstracts a lot, but does most things in a non-standard way. The whole benefit of web components and a 3kb library like lit-element is that there isn't any of that. It's all just web standards.
For example, mixins are not old school. They are for React, but if you're using React 17, you're writing React code. Just because you don't need to write a mixin anymore doesn't mean mixins aren't useful and aren't the recommended way of dealing with browser native classes. Just like events. You normally would never write an
element.addEventListenerin React except for very specific cases. That doesn't mean thataddEventListeneris outdated, that's literally the way you deal with events in the browser.And in reality, I've learned more and more about webcomponents in general, as well as lit-element over the past 2 years, and if I had to boil down my learnings it would be that a lot of stuff React does isn't the "right" way of doing it. It's just "a" way. Just like how Vue and Angular have some non web standard ways of doing things. The right answer to a problem in web components is almost never to port react stuff directly over.
For example, the webcomponent project I work on is embedded in other applications, so it needs to be small. It's a huge, complicated application and I've been able to solve every problem I have with zero external dependencies except for lit-element, just by diving more deeply into the lit-element source code, and taking a look at more advanced webcomponent libraries to see how they do more advanced stuff.
It's really just a slight change in thinking. But for the record, yes I definitely agree with you that more advanced composition can be difficult, but it's possible to achieve just about anything since you're literally just manipulating the DOM with javascript.
Also for people that are really stuck in the React way of thinking, there are actually numerous webcomponent libraries that allows you to pretty much write code identical to React, that outputs a web component.
https://webcomponents.dev/blog/all-the-ways-to-make-a-web-component/ is a great resource - check out the "hook based" section for examples of that.