Mount React components to the DOM using custom elements
npm install remountUse your React components anywhere in your
HTML as web components (custom elements).
Demo ā” Docs
2kb gzip'd · No dependencies · IE support
Remount is available through the npm package repository. React 18 is required.
``sh`npm
npm install remount react react-domyarn
yarn add remount react react-dom
- Via yarn: yarn add remountnpm install remount
- or npm:
Let's start with any React component. Here's one:
`js`
const Greeter = ({ name }) => {
return Hello, {name}!
}
Use _define()_ to define custom elements. Let's define a element:
`js
import { define } from 'remount'
define({ 'x-greeter': Greeter })
`
You can now use it anywhere in your HTML! :boom:
`html`
Some ideas on why you might want to consider Remount for your project:
| | |
| ------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 
| ⨠Adding React to non-SPA apps
You can use React components on any page of a "regular" HTML site. Great for adding React to apps built on Rails or Phoenix. |
| | |
| 
| š Interop with other frameworks
Remount lets you use your React components just like any other HTML element. This means you can use React with Vue, Angular, or any other DOM library/framework. |
- JSON props (eg, ) (docs)
- Named attributes (eg,
- Uses Custom Elements API (when available)
- Fallback to compatible API for other browers
- Shadow DOM mode (when available)
Remount supports all browsers that React 18 supports.
Custom Elements API[#][custom-elements] ("Web Components") will be used if it's available (Chrome/67+), and will fallback to a compatible API otherwise.
[custom-elements]: https://caniuse.com/#search=custom%20elements
- API documentation
- Builds — ES2015+ and ES Module builds are also provided.
- FAQ and Troubleshooting — Start here if you find any issues.
- Comparison with alternatives
- Browser support
remount Ā© 2022, Rico Sta. Cruz. Released under the [MIT] License.
Authored and maintained by Rico Sta. Cruz with help from contributors ([list][contributors]).
> ricostacruz.com ·
> GitHub @rstacruz ·
> Twitter @rstacruz
[mit]: http://mit-license.org/
[contributors]: http://github.com/rstacruz/remount/contributors

