Build Web Components with React using R2WC (react-to-web-component)
dev.to·5d·
Discuss: DEV
🌐Web Development
Preview
Report Post

Web Components are great for distribution: ship one <my-widget> tag and it works in plain HTML, Laravel Blade, Rails, WordPress, or inside another SPA.

React is great for building UIs quickly.

So… why not build your UI in React and ship it as a Web Component?

That’s exactly what R2WC (@r2wc/react-to-web-component) does: it wraps a React component and registers it with customElements.define(...).

In this post, we’ll build two real components:

  • <r2wc-counter> — a typed counter widget (string/number/boolean/json props)
  • <confirm-dialog> — a confirmation modal that emits native DOM events (confirm / cancel)

Why React → Web Components ?

You get:

  • Framework-agnostic reuse: use the same widget in React, Vue, Blade, Astro, etc.
  • **Clean i…

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help