"promisify" a modal and wait for the resolve/reject (react native)

Viewed 96

I have a question about this package: react-modal-promise. It is like a wrapper around a modal, and then you can use the modal as a promise.

An example:

MyModal().then(() => console.log('resolved!')).catch(() => console.log('rejected!'));

The modal component would look like this (simplified!):

const MyModal = () => {
  return (
    <Modal>
      <Pressable onPress={resolve}>
        <Text>Resolve this modal</Text>
      </Pressable>
      <Pressable onPress={reject}>
        <Text>Reject this modal</Text>
      </Pressable>
    </Modal>
  );
};

How can I achieve this in react native? I want to upload a photo to my server. When the user clicks a button, I want to open a modal where the user can select a photo and resolve it, after the modal resolve, the photo should be uploaded.

I know I can include my normal modal inside the JSX code, but I am curious about how this package works.

It's for react native.

0 Answers
Related