3 ms·
I’m not sure what your point is. React components can use Shadow DOM if they want, but they don’t have to. Neither do Web Components. React components can be re
by thomasfoster96 8y ago
I’m not sure what your point is. React components can use Shadow DOM if they want, but they don’t have to. Neither do Web Components. React components can be rendered to DOM nodes, but they can also be rendered to lots of other things.
- flowerlad 8y agoLets say you want to implement this element: <ProductPicker /> You can implement it as a React component in which case it only works in React applications, and will be brittle because of the global nature of js and css. You can implement the same element as a Web Component and now it will work in any application regardless of framework... you can just drop in and it will work. If your application has conflicting css classes or element ids or javascript variables the Web Component will still work reliably. That’s hot! React components will feel a bit cold as cross-framework Web Components take over.
- thomasfoster96 8y ago> and will be brittle because of the global nature of js and css. Modules have existed in JavaScript for several years now, and there are numerous solutions for dealing with global CSS (CSS Modules, Glamor, etc). There are many large production web applications using React, probably generating billions of dollars worth of business - I don’t think they’re “brittle”. > You can implement the same element as a Web Component and now it will work in any application regardless of framework... you can just drop in and it will work. Sure, you can just drop a Web Component into any framework. People use React for a lot more than just defining components - they use it for data fetching, animations, etc. > If your application has conflicting css classes or element ids or javascript variables the Web Component will still work reliably. If this is the case I think you’ve got much bigger problems with your app than choosing which JavaScript library you’re going to use. React apps will work despite conflicting element IDs as well, but they’re still a bug in your app. Web Components don’t magically get rid of JavaScript variables. CSS classes still matter unless your whole app is going to live in the Shadow DOM, which isn’t really what the Shadow DOM is for. > That’s hot! React components will feel a bit cold as cross-framework Web Components take over. Again - you can use both. They solve different problems.
- flowerlad 8y ago>> People use React for a lot more than just defining components - they use it for data fetching, animations, etc. Using React for data fetching and animations seems like a bad idea, it is not the best tool for the job. React is popular today, tomorrow it may be View, then there will be something else. If you can write reusable components that work in all of todays frameworks and tomorrows, while sticking to standards, while taking advantage of things like Shadow DOM, why would you still limit yourself to React? I am not saying the entire application should be a Web Component, but certainly reusable parts should be written as Web Components so that they can work in all your applications even if they don’t all use the same framework and in future applications that use yet-to-be-invented framework.
- deleted 8y ago[deleted]
- thomasfoster96 8y agoThat isn’t really an argument for React or any other framework going out of fashion in the next few weeks though? It seems rather contrived to think that Web Components are inherently better because they’re standardised. React isn’t using unstandardised browser features, and it’s not as though you’re not still reliant upon your chosen Web Components library being maintained in future.
- flowerlad 8y agoWeb Components are directly implemented by browsers so you don’t need a “Web Components library”. So yes they are inherently better because they work in every application and every framework. This universal compatibility and better reliability makes Web Components a better choice today for creating reusable components, than React.
- thomasfoster96 8y ago> Web Components are directly implemented by browsers so you don’t need a “Web Components library”. I mean a collections of components like Polymer. Unless you plan on maintaining everything yourself, both React and Web Components share the same problem here. > This universal compatibility and better reliability makes Web Components a better choice today for creating reusable components, than React. You can mix and match any and all frameworks and Web Components if you try want. And again: React and Web Components mostly solve different problems. One isn’t going to directly cannibalise the other. You can use both.