0.1.1 • Published 3 years ago

react-headless-confirm v0.1.1

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

react-confirmation

Headless, Promise-based confirm component for React.

Example

Build the library:

yarn install && yarn build

Run example:

cd example && yarn install && yarn start

Usage

import { ConfirmProvider, useConfirm } from 'react-headless-confirm';

// ConfirmProvider must be placed on top of your components.
function App() {
  return (
    <ConfirmProvider dialog={YourConfirmDialog}>
      <Example />
    </ConfirmProvider>
  );
}

function Example() {
  const { confirm } = useConfirm();
  const handleConfirm = async () => {
    const isConfirmed = await confirm({
      title: 'Your Title',
      content: 'Your Content',
      confirmText: 'Your Confirm Text',
      cancelText: 'Your Cancel Text',
    });

    // Do something when the user confirm or cancel.
    console.log(isConfirmed);
  }
  return (
    <button onClick={handleConfirm}>Open Confirm</button>
  );
}

License

MIT