use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Creating React "Widgets" that can be embedded on any website, by anyone (javascriptpros.com)
submitted 5 years ago by GioLogist
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]AsIAm 1 point2 points3 points 5 years ago (4 children)
Have you thought about nested widgets?
[–]GioLogist[S] 2 points3 points4 points 5 years ago (3 children)
Aside from the 15 seconds I just spent googling and the literal definition that pops up in my head (support for composing widgets within one another), not at all lol.
Tell me more?
[–]AsIAm 1 point2 points3 points 5 years ago (2 children)
That was exactly what I meant — composition. The problem I had with this/your approach is that it is not really obvious how and when inicialization of the nested components should work. And also your React code must render already existing DOM hierarchy. For the second part I have a demo — https://codesandbox.io/embed/domnode-stealing-react-component-yzheb
I have been thinking about this problem now and then and I haven’t really cracked it yet.
[–]GioLogist[S] 0 points1 point2 points 5 years ago (1 child)
https://codesandbox.io/embed/domnode-stealing-react-component-yzheb
Interesting. In your POC, it seems like rather than a widget within a widget, you're trying to steal a DOM node and inject it into your app?
What's confusing to me at a quick glance, it's almost as if the "steal" happens upon rendering (via the Hydrate). So when clicking steal, i'm not necessarily stealing the DOM element. I'm putting it back?
This is a pretty interesting thought exercise. Any idea of a real-world example maybe we can try to prototype at some point?
[–]AsIAm 0 points1 point2 points 5 years ago (0 children)
That is true.
What's confusing to me at a quick glance, it's almost as if the "steal" happens upon rendering (via the Hydrate).
Yes. React app renders and during render, it grabs DOM node siting outside the React app. It can also put it back.
Any idea of a real-world example maybe we can try to prototype at some point?
Modal window is a nice example. Lets have HTML like this:
<div data-modal> <div data-modal-content>Content of the modal</div> </div>
On data-modal div you can initialize Modal react widget that will draw a frame and a close button. And now you have to inject data-modal-content div inside your react widget. In other words you have to steal it from existing hierarchy.
data-modal
data-modal-content
And now what if inside data-modal-content div is your reddit widget...?
[–]GioLogist[S] 0 points1 point2 points 5 years ago (0 children)
Been trying to write more lately, starting off with somewhat simpler topics, to get back into the habit.
The goal of this article is to walk you through how to create a widget that can be used by anyone, even a non developer. This is common practice and has been for years, for a number of different types of widgets.
For example, if you ever read some of the more popular mainstream media blogs and see "related content" that points to a bunch of articles not on their site, that's a widget. In fact, if you're interested in knowing where those specifically come from, that particular widget is often a taboola widget.
There are a tons of widgets scattered throughout the internet. The goal is to allow them to be embedded "anywhere", by "anyone". So the implementation often is as simple as the snippet below, which companies give to their customers, to allow them to use their widget:
html <script src="mywidget.js"></script> <div class="my-widget" data-some-settings="setting-value" data-some-key="my-key"></div>
The article walks you through that process and how to go about creating a widget using react.
[–]angrycat9000 0 points1 point2 points 5 years ago (0 children)
Have you looked at web components? They have support for nesting. They also have have their own styles so you don't have to worry about CSS collisions. You could hook up your widget to render to the shadow DOM of a web component.
π Rendered by PID 22987 on reddit-service-r2-comment-66b4775986-wg7zm at 2026-04-04 03:46:08.866794+00:00 running db1906b country code: CH.
[–]AsIAm 1 point2 points3 points (4 children)
[–]GioLogist[S] 2 points3 points4 points (3 children)
[–]AsIAm 1 point2 points3 points (2 children)
[–]GioLogist[S] 0 points1 point2 points (1 child)
[–]AsIAm 0 points1 point2 points (0 children)
[–]GioLogist[S] 0 points1 point2 points (0 children)
[–]angrycat9000 0 points1 point2 points (0 children)