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: packages/legacy/README.md
+11-26Lines changed: 11 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,10 +2,12 @@
2
2
3
3
`react-to-webcomponent` converts [React](https://reactjs.org/) components to [custom elements](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements)! It lets you share React components as native elements that **don't** require mounted being through React. The custom element acts as a wrapper for the underlying React component. Use these custom elements with any project that uses HTML even in any framework (vue, svelte, angular, ember, canjs) the same way you would use standard HTML elements.
4
4
5
+
> Note: This is a compatibility wrapper around our new, simpler API. We highly reccomend using the new [@r2wc/react-to-web-component](https://github.com/bitovi/react-to-web-component) package.
6
+
5
7
`react-to-webcomponent`:
6
8
7
9
- Works in all modern browsers. (Edge needs a [customElements polyfill](https://github.com/webcomponents/polyfills/tree/master/packages/custom-elements)).
8
-
- Is `1.11KB` minified and gzipped.
10
+
- Is `1.37KB` minified and gzipped.
9
11
10
12
## Need help or have questions?
11
13
@@ -30,8 +32,9 @@ With our React component complete, all we have to do is call `r2wc` and [customE
30
32
31
33
```js
32
34
importReactfrom"react"
33
-
import*asReactDOMfrom"react-dom/client"// if using React 18
34
-
// import * as ReactDOM from "react-dom" // if using React 17
35
+
importReactDOMfrom"react-dom/client"// if using React 18
36
+
// import ReactDOM from "react-dom" // if using React 17
37
+
35
38
importr2wcfrom"react-to-webcomponent"
36
39
37
40
constWebGreeting=r2wc(Greeting, React, ReactDOM)
@@ -87,22 +90,15 @@ We also have a [complete example using a third party library](docs/complete-exam
87
90
To install from npm:
88
91
89
92
```
90
-
npm i react-to-webcomponent
93
+
npm install react-to-webcomponent
91
94
```
92
95
93
-
## External Examples
94
-
95
-
Greeting example in a [CodePen](https://codepen.io/bavinedwards/pen/jOveaGm)
96
-
97
-
Greeting example in [CodeSandbox](https://codesandbox.io/s/sample-greeting-app-ts-qwidh9)
98
-
99
-
Hello, world example (React17) in [CodeSandbox](https://codesandbox.io/s/hello-world-react17-u4l3x1)
96
+
## Examples
100
97
101
-
Example with all prop types in [CodeSandbox](https://codesandbox.io/p/sandbox/vite-example-with-numerous-types-gjf87o)
Check out our [full API documentation](../../docs/api.md).
114
110
115
-
`r2wc` creates a constructor function whose prototype is a [Proxy](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy). This acts as a trap for any property set on instances of the custom element. When a property is set, the proxy:
116
-
117
-
- re-renders the React component inside the custom element.
118
-
- creates an enumerable getter / setter on the instance
119
-
to save the set value and avoid hitting the proxy in the future.
120
-
121
-
Also:
122
-
123
-
- Enumerable properties and values on the custom element are used as the `props` passed to the React component.
124
-
- The React component is not rendered until the custom element is inserted into the page.
125
-
126
111
# We want to hear from you.
127
112
128
113
Come chat with us about open source in our Bitovi community [Discord](https://discord.gg/J7ejFsZnJ4).
Copy file name to clipboardExpand all lines: packages/react-to-web-component/README.md
+7-25Lines changed: 7 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,10 +2,12 @@
2
2
3
3
`@r2wc/react-to-web-component` converts [React](https://reactjs.org/) components to [custom elements](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements)! It lets you share React components as native elements that **don't** require mounted being through React. The custom element acts as a wrapper for the underlying React component. Use these custom elements with any project that uses HTML even in any framework (vue, svelte, angular, ember, canjs) the same way you would use standard HTML elements.
4
4
5
+
> Note: This package only works with the React 16 and 17. If you are using React 18, use version 2.0 or later.
6
+
5
7
`@r2wc/react-to-web-component`:
6
8
7
9
- Works in all modern browsers. (Edge needs a [customElements polyfill](https://github.com/webcomponents/polyfills/tree/master/packages/custom-elements)).
8
-
- Is `1.11KB` minified and gzipped.
10
+
- Is `1.26KB` minified and gzipped.
9
11
10
12
## Need help or have questions?
11
13
@@ -46,8 +48,6 @@ Now we can use `<web-greeting>` like any other HTML element!
46
48
</body>
47
49
```
48
50
49
-
Note that by using React 18, `r2wc` will use the new root API. If your application needs the legacy API, please use React 17
50
-
51
51
In the above case, the web-greeting custom element is not making use of the `name` property from our `Greeting` component.
52
52
53
53
## Working with Attributes
@@ -89,19 +89,12 @@ To install from npm:
89
89
npm install @r2wc/react-to-web-component
90
90
```
91
91
92
-
## External Examples
93
-
94
-
Greeting example in a [CodePen](https://codepen.io/bavinedwards/pen/jOveaGm)
95
-
96
-
Greeting example in [CodeSandbox](https://codesandbox.io/s/sample-greeting-app-ts-qwidh9)
97
-
98
-
Hello, world example (React17) in [CodeSandbox](https://codesandbox.io/s/hello-world-react17-u4l3x1)
92
+
## Examples
99
93
100
-
Example with all prop types in [CodeSandbox](https://codesandbox.io/p/sandbox/vite-example-with-numerous-types-gjf87o)
Check out our [full API documentation](../../docs/api.md).
113
106
114
-
`r2wc` creates a constructor function whose prototype is a [Proxy](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy). This acts as a trap for any property set on instances of the custom element. When a property is set, the proxy:
115
-
116
-
- re-renders the React component inside the custom element.
117
-
- creates an enumerable getter / setter on the instance
118
-
to save the set value and avoid hitting the proxy in the future.
119
-
120
-
Also:
121
-
122
-
- Enumerable properties and values on the custom element are used as the `props` passed to the React component.
123
-
- The React component is not rendered until the custom element is inserted into the page.
124
-
125
107
# We want to hear from you.
126
108
127
109
Come chat with us about open source in our Bitovi community [Discord](https://discord.gg/J7ejFsZnJ4).
0 commit comments