npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wechat-h5-to-mini-program-hoc

v0.0.4

Published

A common solution for navigating to mini-program from wechat h5 environment.

Downloads

2

Readme

微信 H5 跳转小程序页面通用解决方案

一个开箱即用的微信H5跳转微信小程序的 HOC 组件

背景

对于H5开发来说,微信H5这一媒介想必大家并不陌生。微信作为目前国内最大的互联网生态环境,其内置浏览器与小程序的流量可谓是不可轻视。

我们知道,H5的功能局限性较大,并不能胜任许多涉及到关系列表以及部分原生能力的功能,越来越多的需求希望能够将用户从微信H5的平台导流至小程序,以实现原生能力的调用。

而在导流需求的开发过程中,微信js sdk原生标签的独特性与逻辑的复杂性使得许多开发者踩坑无数。基于此,本仓库将此类原生标签进行封装,提供对应的生命周期钩子,提供开箱即用的 HOC 组件。

优势

  1. 开箱即用:提供完备通用的能力封装,仅需暴露最少的组件 props 供接入方传入

  2. 轻量:全 ESM 打包,引入成本极低

  3. 生命周期:暴露生命周期钩子与上报工具,提供日志调试能力与上报能力的拓展

技术栈

TypeScript + React Hooks

使用方法

1. 安装

npm i wechat-h5-to-mini-program-hoc

2. 使用

// normal import
import WechatH5ToMiniProgramHOC from wechat-h5-to-mini-program-hoc;
// dynamic import 
// const WechatH5ToMiniProgramHOC = lazy(() => import('wechat-h5-to-mini-program-hoc'));

import { ComponentA, ComponentB } from './components';

const demoApp = (props) => {
  useEffect(() => {
    // some business logic ...
  }, []);

  // 调用业务方法,获取微信签名。
  // 通常需要通过业务后台下发,建议封装成 Promise 或者异步函数
  const getWxSignature = useCallback(async () => {
      const { nonceStr, signature, timestamp } = await fetch('XXXXX', {
          credentials: 'include',
      }).then(resp => resp.json());

      return {
        beta: true,
        appId: 'XXXXXX',  // 公众号 APPId
        timestamp,
        nonceStr,
        signature,
      };
    }, []);

  return (
    <div>
      <ComponentA />
      <WechatH5ToMiniProgramHOC
        targetPath='packages/mini-program/pageA'
        miniProgramAppId='gh_XXXX'
        wxSignatureFetcher={getWxSignature}
      >
        <ComponentB>
      </WechatH5ToMiniProgramHOC>
    </div>
  )
}