You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+64-3
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,16 @@
2
2
3
3
Build and export React Components as Web Components without any extra effort.
4
4
5
+
Size = ~3kb after gzip
6
+
7
+
# Use cases
8
+
9
+
- Export existing react components as web components so you can use them with Vue or Angular.
10
+
- Use rich react api to build web components with state management/etc
11
+
- Lets say you are writing a component library with web components but you already have a huge collection of component in react.You can use this library to generate a component library with the existing components. And then safely continue to rewrite each one of them behind the scene. This makes sure other teams are not waiting for you to finish.
12
+
- For more crazy people - You can even export your entire react app as a web component and embed it into another app made with Angular or Vue. So you can keep writing newer parts of code in react while keeping your legacy code working on the side.
13
+
- Maybe (not tried) you can embed another old react app (wrapped with this module) inside ur current react app.
14
+
5
15
# Install
6
16
7
17
```
@@ -16,7 +26,9 @@ yarn add react-webcomponentify
16
26
17
27
# Usage
18
28
19
-
**Basic**
29
+
### Basic
30
+
31
+
**Simple use case**
20
32
21
33
```js
22
34
importReactfrom"react";
@@ -42,7 +54,11 @@ In HTML:
42
54
</html>
43
55
```
44
56
45
-
**Advanced**
57
+
### Advanced
58
+
59
+
**Sending non string props to react**
60
+
61
+
You can send serializable string props via the html attributes itself. But for props like callback functions or complex objects you can use the `setProps` method on the element as shown below.
46
62
47
63
```js
48
64
importReactfrom"react";
@@ -88,4 +104,49 @@ element.setProps({
88
104
})
89
105
```
90
106
91
-
# More detailed examples and scenarios coming soon...
This will send `<p>Some Child</p>` via this.props.children to the React component `ComponentWithChild`.
145
+
Note that `<p>Some Child</p>` is a dom node and not a react component. So it will be wrapped with a simple react component found here: https://github.com/master-atul/react-webcomponentify/blob/master/src/react-dom-child.js
146
+
But for implementation purposed use it like a regular child component.
0 commit comments