Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/yunho1017/react-opener

render React Component from anywhere
https://github.com/yunho1017/react-opener

Last synced: about 2 months ago
JSON representation

render React Component from anywhere

Awesome Lists containing this project

README

        

# react-opener

[![npm](https://img.shields.io/npm/v/react-opener)](https://www.npmjs.com/package/react-opener)
[![size](https://img.shields.io/bundlephobia/minzip/react-opener)](https://bundlephobia.com/result?p=react-opener)

render React Component from anywhere!

[Demo](https://react-opener.vercel.app/)

## Introduction

Previously in order to show Dialog in React, we had to write the code below

```js
const Component = () => {
const [open, setOpen] = useState(false);

return (


{
setOpen(true);
}}
>
open dialog

{
setOpen(false);
}}
/>


);
};
```

The code above has Dialog-Related code throughout the Function Component.

If components become complicated, readability becomes poor and maintenance becomes difficult.

This library can show React Component from anywhere to solve this issues.

## Install

This package has peer dependencies, which you need to install by yourself.

```bash
// npm
npm install react-opener react

// yarn
yarn add react-opener react
```

## Usage

### Basic

```javascript
import { ReactOpener, ReactToastOpener } from "react-opener";

const ToastStore = ReactToastOpener.createStore();
const DialogStore = ReactOpener.createStore();

const Container = () => {
return (


{
ToastStore.success("toast !");
}}
>
toast

{
DialogStore.open({
element: ({ close }) => ,
});
}}
>
dialog

// Rendered here !



);
};
```

### useOpener

```javascript
import { ReactOpener } from "react-opener";

const Container = () => {
const [dialog, opener] = ReactOpener.useOpener();

return (


{
dialog.open({
element: ({ close }) => ,
});
}}
>
dialog

{opener}

);
};
```