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

@vtils/taro

v2.59.0

Published

vtils 在 Taro 中的应用。

Downloads

20

Readme

安装

# yarn
yarn add vtils @vtils/taro

# or, npm
npm i vtils @vtils/taro --save

使用

import { useToggle } from '@vtils/taro'

export default function Edit() {
  const [showMore, toggleShowMore] = useToggle(false)
  return (
    // ...
  )
}

导出自 react-use 的 Hooks

导出自 @vtils/react 的工具函数、Hooks

自产的工具函数、Hooks 目录

👇 | 👇 | 👇 --- | --- | --- getCurrentPageUrl | useAccountInfo | useCurrentPageUrl useLaunchOptions | useLoading | useMenuButtonBoundingClientRect useNavigationBarLoading | useNavigationBarTitle | useQuery useScope | useScrollLoadMore | useSystemInfo

自产的工具函数、Hooks 列表

getCurrentPageUrl

源码 | API | 回目录

获取当前页面的绝对路径,包含查询参数。

const currentPageUrl = getCurrentPageUrl()
// => /pages/Product/Detail?id=10

useAccountInfo

源码 | API | 回目录

获取当前帐号信息。

const accountInfo = useAccountInfo()
// {
//   miniProgram: {
//     appId: '小程序 appid'
//   },
//   plugin: {
//     appId: '插件 appid',
//     version: '插件版本号'
//   }
// }

useCurrentPageUrl

源码 | API | 回目录

获取当前页面的绝对路径,包含查询参数。

const currentPageUrl = useCurrentPageUrl()

if (currentPageUrl) {
  // => /pages/Product/Detail?id=10
}

useLaunchOptions

源码 | API | 回目录

获取小程序启动时的参数。

const launchOptions = useLaunchOptions()
// { path: '启动小程序的路径', ... }

useLoading

源码 | API | 回目录

使用加载提示。

const getDetail = useAsync(async () => {
  return getDetailApi()
})
useLoading(getDetail.loading, '获取数据中...')

useMenuButtonBoundingClientRect

源码 | API | 回目录

获取菜单按钮(右上角胶囊按钮)的布局位置信息。坐标信息以屏幕左上角为原点。

const rect = useMenuButtonBoundingClientRect()
// { width: 333, ... }

useNavigationBarLoading

源码 | API | 回目录

控制导航条加载动画的显示、隐藏。

// 加载列表数据时显示导航条加载动画
const [loading, setLoading] = useState(true)
useNavigationBarLoading(loading)
useEffect(() => {
  setLoading(true)
  getListApi().then(() => {
    setLoading(false)
  })
}, [])

useNavigationBarTitle

源码 | API | 回目录

动态设置当前页面的标题。

// 以产品名称作为页面标题
const [product, setProduct] = useState({})
useNavigationBarTitle(product.name || '')
useEffect(() => {
  getProductDetail().then(setProduct)
}, [])

useQuery

源码 | API | 回目录

获取页面的查询参数,会将类型为数值的参数值转为数字。

const query = useQuery<{ id: number }>()
useEffect(() => {
  if (query.id != null) {
    console.log(typeof query.id, query.id)
    // 假设页面的查询参数为 id=100,则输出为:'number', 100
  }
}, [query.id])

useScope

源码 | API | 回目录

获取小程序原生作用域。同类组件中的 this.$scope

const scope = useScope()
useEffect(() => {
  if (scope) {
    const ctx = Taro.createCanvasContext('canvas', scope)
    // ...
  }
}, [scope])

useScrollLoadMore

源码 | API | 回目录

滚动数据加载。

const [catId, setCatId] = useState(1)

const loader = useScrollLoadMore(
  // 在这里加载数据
  payload => {
    return getListByCatId({
      id: catId,
      pageNumber: payload.pageNumber
    }).then(res => {
      // 返回的数据结构必须为一个对象或数组,对象的结构如下,
      // 若返回数组,当数组为空时即视为加载完成
      return {
        data: res.data,
        total: res.total
      }
    })
  },
  // 依赖若发生变化则从首页重新加载数据
  [catId]
)

const handleCatChange = useCallback((catId: number) => {
  setCatId(catId)
}, [])

console.log(loader.loading) // 是否正在加载中
console.log(loader.initialLoading) // 是否初次加载中,重新加载也视为初次加载
console.log(loader.incrementalLoading) // 是否增量加载中
console.log(loader.noMore) // 数据是否已加载完成
console.log(loader.pageNumber) // 已经加载到多少页
console.log(loader.total) // 数据总量

useSystemInfo

源码 | API | 回目录

获取系统信息。

const systemInfo = useSystemInfo()
// { screenWidth: 750, ... }

许可

MIT ©️ Jay Fong