1.1.0 • Published 5 years ago

react-moised v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

React Moised

React + Modal + Promises = <3

Installation

yarn add react-moised

Live demo

A demo is worth a thousand words

How to use

  1. Put the Moised provider in your equivalent App.js file.
import React from 'react'
import { Moised } from 'react-moised'

function App() {
  return (
    <div>
      <Moised />
    </div>
  )
}
  1. Create you own modal
import React from 'react'
import { withMoised } from 'react-moised'

function Dialog(props) {
  return (
    <>
      <button onClick={props.onSubmit}>Submit</button>
      <button onClick={props.onDismiss}>Dismiss</button>
    </>
  )
}

and export wrapping with withMoised method:

export default () => withMoised(Dialog)

Note: It's possible to export Dialog waiting for props when called as below:

export default (props) => withMoised(Dialog, props)
  1. And that's it, use anywhere as promise:
import React from 'react'
import Dialog from './Dialog'

function Homepage() {
  const handleDialog = async () => {
    const confirmed = await Dialog()

    if (confirmed) console.log('confirmed')
  }

  return (
    <div>
      <button onClick={handleDialog}>Dialog</button>
    </div>
  )
}
1.1.0

5 years ago

1.0.0

5 years ago