Giter Club home page Giter Club logo

react-async-popup's Introduction

react-async-popup

A 1kb promise based popup (confirm and modal) library for react, to reduce extra state management needed for popups. checkout the docs here - https://aadil.dev/react-async-popup

Install

npm install --save react-async-popup

or

yarn add react-async-popup

Usage

With Hooks -

import React from 'react'
import { useConfirm } from 'react-async-popup'

export default function App() {
  const [showConfirm] = useConfirm({
    title: 'Are you sure ?'
  })

  const openConfirm = async () => {
    const result = await showConfirm()

    if (result === true) {
      console.log('I am sure')
    } else {
      console.log('not sure')
    }
  }

  return <button onClick={openConfirm}> Open Confirm </button>
}

Without Hooks -

import React from 'react'

import { Confirm } from 'react-async-popup'

function App() {
  const onDelete = async () => {
    const { show } = await Confirm.new()

    const result = await show({
      title: ' Are you sure you want to delete the file ?'
    })

    if (result === true) {
      console.log(' Yes, Delete the file ')
    } else {
      console.log(" Don't delete ")
    }
  }

  return <button onClick={openConfirm}> Open Confirm </button>
}

Find more examples here - https://aadil.dev/react-async-popup/examples

License

MIT © aadilhasan

react-async-popup's People

Contributors

aadilhasan avatar dependabot[bot] avatar jasepellerin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

react-async-popup's Issues

A ton of empty divs

I was trying out this package, and the page I added a popup to seems to have a ton of empty <div> elements in the DOM. This screenshot is the DOM while the popup hasn't been opened yet.

image

Example with hooks not working

Following the example using hooks I am getting the follow error

TypeError: showConfirm is not a function

My IDE is also complaining TS2721: Cannot invoke an object which is possibly 'null'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.