react-dialog-async
TypeScript icon, indicating that this package has built-in type declarations

2.3.1 • Public • Published

React Dialog Async

npm Types Downloads

React Dialog Async provides a simple hook-based API for managing dialog state in React apps.

  • ✅ CSS Framework agnostic - works with any component library or CSS setup
  • ✅ Lightweight with zero dependencies
  • ✅ Written in Typescript
  • ✅ Supports both React and React Native

✨ Read the docs here ✨

Quick Start

This example demonstrates how to create a simple dialog that asks the user a question and logs their response to the console:

// 1. Wrap your app with DialogProvider
<DialogProvider>
  <App />
</DialogProvider>

// 2. Create a dialog component
const QuestionDialog = ({ data, open, handleClose }) => {
  if (!open) return null; // Don't render if the dialog is closed

  return (
    <div className={'dialog'}>
        <p>{data.question}</p>
        <button onClick={() => handleClose("No")}>No</button>
        <button onClick={() => handleClose("Yes")}>Yes</button>
    </div>
  )
};

// 3. Use the useDialog hook to show the dialog
const App = () => {
  const questionDialog = useDialog(QuestionDialog);

  const handleClick = async () => {
    const response = await questionDialog.show({
      // pass data to the dialog 
      question: "Do you like apples?" 
    }); 
    
    console.log(response) // Will be either "Yes" or "No"
  };

  return (
      <button onClick={handleClick}>
        Ask me a question
      </button>
  );
};

Contributing

Contributions are more than welcome!

If you have a use-case that the library currently doesn't support please raise it in an issue or pull request 😄

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
2.3.18latest

Version History

VersionDownloads (Last 7 Days)Published
2.3.18
2.3.0133
2.2.01
2.1.10
2.1.00
2.0.20
2.0.10
2.0.00
1.3.331
1.3.20
1.3.11
1.2.181
1.2.0430
1.1.10
1.1.00
1.0.82
1.0.71
1.0.60
1.0.50
1.0.40
1.0.30
1.0.21
1.0.10
1.0.00

Package Sidebar

Install

npm i react-dialog-async

Weekly Downloads

508

Version

2.3.1

License

MIT

Unpacked Size

18.9 kB

Total Files

6

Last publish

Collaborators

  • halcyon400