0.0.2 • Published 3 years ago

react-use-confirm v0.0.2

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

react-use-confirm

Made with create-react-library

NPM JavaScript Style Guide

Install

npm install --save react-use-confirm

Usage

import { ConfirmProvider } from 'react-use-confirm';
// You can check how to implement you own component here:
// https://github.com/ndeviant/react-use-confirm/blob/master/example/src/PoorConfirm.jsx
// Or how to use with MUI:
// https://github.com/ndeviant/react-use-confirm/blob/master/example/src/MuiDialogConfirm.jsx
import YourCustomConfirmComponent from './YourCustomConfirmComponent';

function App() {
  return (
    <ConfirmProvider
      ConfirmComponent={YourCustomConfirmComponent}
      anyDefaultProp="couldBeRewrited"
      byOpenConfirmFunction
      variant="success"
    >
      {children}
    </ConfirmProvider>
)
import React from 'react'

import { useConfirm } from 'react-use-confirm';

function Example {
  const { openConfirm, closeConfirm } = useConfirm();

  return (
    <button onClick={async () => {
        await openConfirm({
          title: 'Are you sure?',
          actions: <button onClick={closeConfirm}>Ok</button>
        });

        alert('I will be called only after closing of confirm!')
      }}
    >
      Open confirm
    </button>)
}

License

MIT © ndeviant