https://github.com/iamogbz/react-mirror
🪞 Create synchronized replicas of a DOM element using React
https://github.com/iamogbz/react-mirror
mirror portal react react-dom react-mirror react-portal
Last synced: 10 months ago
JSON representation
🪞 Create synchronized replicas of a DOM element using React
- Host: GitHub
- URL: https://github.com/iamogbz/react-mirror
- Owner: iamogbz
- License: unlicense
- Created: 2020-03-20T03:10:45.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2025-04-29T10:47:19.000Z (10 months ago)
- Last Synced: 2025-04-30T07:49:36.452Z (10 months ago)
- Topics: mirror, portal, react, react-dom, react-mirror, react-portal
- Language: TypeScript
- Homepage: http://ogbizi.com/react-mirror/
- Size: 76.1 MB
- Stars: 14
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# React Mirror

[](https://www.npmjs.com/package/react-mirror)
[](https://app.dependabot.com)
[](https://libraries.io/github/iamogbz/react-mirror)
[](https://github.com/iamogbz/react-mirror/actions)
[](https://coveralls.io/github/iamogbz/react-mirror)
Create synchronized replicas of a React DOM element
> Suggested alternative for non react usage [mirror-element](https://github.com/iamogbz/oh-my-wcs/blob/main/components/el-mirror.md)
## Usage
See equivalent uses of the hook and component below.
### `useMirror` hook
```jsx
import { useMirror } from 'react-mirror';
function App() {
const [ref, mirror] = useMirror({ className: 'mirror-frame' });
return (
<>
{mirror}
>
);
}
```
### `` component
```jsx
import React from 'react';
import { Mirror } from 'react-mirror';
function App() {
const [reflect, setReflect] = React.useState(null);
return (
<>
>
);
}
```
### `` component
You can also render a reflection, with all the styles needed, in a separate window using the magic of [`Portals`](https://reactjs.org/docs/portals.html) 🌀
```jsx
import React from 'react';
import { FrameStyles, Reflection, Window } from 'react-mirror';
function App() {
const [reflect, setReflect] = React.useState(null);
return (
<>
>
);
}
```
## Demos
### Using Portals
- [Live Preview](https://ogbizi.com/react-mirror/) ([source](demo))
## Alternatives
- Simple HTML custom [mirror-element](https://github.com/iamogbz/oh-my-wcs/blob/main/components/el-mirror.md)
- [Curious case of independent genesis](https://github.com/Theadd/react-mirror#readme)