“ promisify”模态并等待分辨/拒绝(react Antial)

发布于 2025-02-04 11:16:50 字数 838 浏览 0 评论 0原文

我对此软件包有一个问题: reaction-modal-promise 。它就像围绕模态周围的包装器,然后您可以将模态用作承诺。

一个示例:

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

模态组件看起来像这样(简化!):

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

如何在React Native中实现这一目标?我想将照片上传到我的服务器。当用户单击一个按钮时,我想打开一个模态,用户可以在其中选择照片并在模态解析后解析它,应上传照片。

我知道我可以在JSX代码中加入我的普通模态,但我对此软件包的工作方式感到好奇。

它是针对本地的。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文