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
+19-38
Original file line number
Diff line number
Diff line change
@@ -2,10 +2,20 @@
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 being mounted 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: The latest version of this package only works with the React 18. If you are using React 16 or 17, please use version 1.
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.
11
+
12
+
## Setup
13
+
14
+
To install from npm:
15
+
16
+
```
17
+
npm install @r2wc/react-to-web-component
18
+
```
9
19
10
20
## Need help or have questions?
11
21
@@ -46,8 +56,6 @@ Now we can use `<web-greeting>` like any other HTML element!
46
56
</body>
47
57
```
48
58
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
59
In the above case, the web-greeting custom element is not making use of the `name` property from our `Greeting` component.
52
60
53
61
## Working with Attributes
@@ -81,25 +89,15 @@ For projects needing more advanced usage of the web components, see our [program
81
89
82
90
We also have a [complete example using a third party library](docs/complete-example.md).
83
91
84
-
## Setup
85
-
86
-
To install from npm:
92
+
## Examples
87
93
88
-
```
89
-
npm install @r2wc/react-to-web-component
90
-
```
94
+
*[Hello World](https://codesandbox.io/s/hello-world-md5oih) - The quintessential software demo!
95
+
*[All the Props](https://codesandbox.io/s/all-the-props-n8z5hv) - A demo of all the prop transform types that R2WC supports.
96
+
*[Header Example](https://codesandbox.io/s/example-header-blog-7k313l) - An example reusable Header component.
97
+
*[MUI Button](https://codesandbox.io/s/example-mui-button-qwidh9) - An example application using an MUI button with theme customization.
98
+
*[Checklist Demo](https://codesandbox.io/s/example-checklist-blog-y3nqwx) - An example Checklist application.
91
99
92
-
## External Examples
93
-
94
-
Greeting example in [CodeSandbox](https://codesandbox.io/s/sample-greeting-app-ts-qwidh9)
95
-
96
-
Hello, world example (React17) in [CodeSandbox](https://codesandbox.io/s/hello-world-react17-u4l3x1)
97
-
98
-
Example with all prop types in [CodeSandbox](https://codesandbox.io/p/sandbox/vite-example-with-numerous-types-gjf87o)
99
-
100
-
R2WC With Vite Header Example in [CodeSandbox](https://codesandbox.io/p/sandbox/r2wc-header-example-vqzfgo)
101
-
102
-
## External Blog Posts
100
+
## Blog Posts
103
101
104
102
R2WC with Vite [View Post](https://www.bitovi.com/blog/react-everywhere-with-vite-and-react-to-webcomponent)
105
103
@@ -112,30 +110,13 @@ Check out our [full API documentation](https://github.com/bitovi/react-to-web-co
112
110
Under the hood, `r2wc` creates a `CustomElementConstructor` with custom getters/setters and life cycle methods that keep track of the props that you have defined. When a property is set, its custom setter:
113
111
114
112
- re-renders the React component inside the custom element.
115
-
- creates an enumerable getter / setter on the instance
116
-
to save the set value and avoid hitting the proxy in the future.
113
+
- creates an enumerable getter / setter on the instance to save the set value and avoid hitting the proxy in the future.
117
114
118
115
Also:
119
116
120
117
- Enumerable properties and values on the custom element are used as the `props` passed to the React component.
121
118
- The React component is not rendered until the custom element is inserted into the page.
122
119
123
-
# Tests
124
-
125
-
To run tests, first run:
126
-
127
-
```
128
-
npm run buildtests
129
-
```
130
-
131
-
This copies the root test file into each of the `/tests/react*` versioned folders, modifies the ReactDOM import for older versions, and installs the corresponding version of react in that directory.
132
-
133
-
Then run:
134
-
135
-
```
136
-
npm run test
137
-
```
138
-
139
120
# We want to hear from you.
140
121
141
122
Come chat with us about open source in our Bitovi community [Discord](https://discord.gg/J7ejFsZnJ4).
0 commit comments