Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: requestSubscribeMessage无法获取点击返回值 #24

Closed
jianhao2010303 opened this issue Apr 23, 2022 · 1 comment
Closed

bug: requestSubscribeMessage无法获取点击返回值 #24

jianhao2010303 opened this issue Apr 23, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@jianhao2010303
Copy link

版本

  • taro-hooks: 1,5,7
  • taro: 3.4.7
  • node:
  • npm:
  • OS:
  • Browser:

小程序

复现步骤

  1. 使用小程序增加按钮,增加回调方法:
    const { subscribeIds: result } = await requestSubscribeMessage(subscribeIds)
  2. 弹出确认授权后点击确认。
  3. 断点查看 result返回值。

你期望的现象?

返回: accept 或 拒绝。

现有的现象?

result 返回 undefined

复现 repo(最好可以提供一个复现的 repo)

@jianhao2010303 jianhao2010303 added the bug Something isn't working label Apr 23, 2022
@innocces
Copy link
Owner

image
=。- 可以参考一下代码自行debug一下

import React, { useCallback } from "react";
import { View, Text, Button, Image } from "@tarojs/components";
import { useEnv, useNavigationBar, useModal, useToast, useRequestSubscribeMessage } from "taro-hooks";
import logo from "./hook.png";

import './index.less'

const Index = () => {
  const env = useEnv();
  const [requestSubscribeMessage] = useRequestSubscribeMessage();
  const [_, { setTitle }] = useNavigationBar({ title: "Taro Hooks" });

  const [show] = useModal({
    title: "Taro Hooks!",
    showCancel: false,
    confirmColor: "#8c2de9",
    confirmText: "支持一下",
    mask: true,
  });
  const [showToast] = useToast({ mask: true });

  const handleModal = useCallback(() => {
    show({ content: "不如给一个star⭐️!" }).then(() => {
      showToast({ title: "点击了支持!" });
    });
  }, [show, showToast]);

  const handleRequestSubscribeMessage = useCallback(async () => {
    let content = '订阅成功!';
    const subscribeId = 'jeNEwprDztjgwq0BI1raBmcJ7Sw1ldt-8lRi-7jXeyY';
    try {
      const { [subscribeId]: result } = await requestSubscribeMessage([
        subscribeId,
      ]);
      if (result !== 'accept') {
        content = '订阅失败';
      }
    } catch (e) {
      content = '订阅失败';
    }
    show({ content });
  }, [requestSubscribeMessage, show]);

  return (
    <View className="wrapper">
      <Image className="logo" src={logo} />
      <Text className="title">为Taro而设计的Hooks Library</Text>
      <Text className="desc">
        目前覆盖70%官方API. 抹平部分API在H5端短板. 提供近40+Hooks!
        并结合ahook适配Taro!
      </Text>
      <View className="list">
        <Text className="label">运行环境</Text>
        <Text className="note">{env}</Text>
      </View>
      <Button className="button" onClick={handleRequestSubscribeMessage}>订阅</Button>
      <Button className="button" onClick={() => setTitle("Taro Hooks Nice!")}>
        设置标题
      </Button>
      <Button className="button" onClick={handleModal}>
        使用Modal
      </Button>
    </View>
  );
};

export default Index;

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants