eBay / nice-modal-react

A modal state manager for React.
https://ebay.github.io/nice-modal-react
MIT License
1.96k stars 110 forks source link

Check Promise status #4

Closed plckr closed 2 years ago

plckr commented 2 years ago

Hello once again,

Looking at the documentation I could not find the answer. I'm trying to implement a loading inside my modal, after the user submits (resolves, or rejects the promise)

For that, I thought about know if the Promise is Pending or Resolves/Rejected if Resolves/rejected the loading should appear

I suggest add a isPending property for example

Example code after the implementation

{!isPending && <span>Loading ...</span>}
supnate commented 2 years ago

You may need use a separate state for such cases:

const [pending, setPending] = useState(false);
const showModal = () => {
  setPending(true);
  modal.show(MyModal, {}).then(() => {
    setPending(false);
  }
}

Or, you just handle pending state inside a modal.

plckr commented 2 years ago

This is the solution I first remembered. But thought you wanted to implement inside the library. In that case this issue can be closed 👍