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

test-wsk

v1.0.4

Published

对工作中常用到业务进行hooks再次封装。 ## 使用

Downloads

1

Readme

wsk-hooks

对工作中常用到业务进行hooks再次封装。

使用

yarn add wsk-hooks

useReactive

useState 的封装。

应用场景:响应式变量(自由设置变量的值,并且可以随时获取到变量的最新值)。

const state = useReactive<any>({
  count: 0,
  name: 'wskang',
  flag: true,
  arr: [],
  bugs: ['wskang', 'react', 'hook'],
  addBug(bug: string) {
    this.bugs.push(bug);
  },
  get bugsCount() {
    return this.bugs.length;
  },
})

useTimeout

setTimeout 的封装。

应用场景:一段时间后,要执行一次函数。

useTimeout(() => {
  setT(n + 1)
}, 1000)

useUnmount

useEffect 的封装。

应用场景:类似 componentWillUnmount 功能,组件即将卸载时。

useUnmount(() => {
   message.info('组件已卸载')
})

useUpdate

useCallback 的封装。

应用场景:组件强制更新。

const update = useUpdate();

useCountDown

useLatest, useState, useEffect, useMemo 的封装。

应用场景:倒计时。

const [_, formattedRes] = useCountDown({
  targetDate: '2022-12-31 24:00:00',
});
const { days, hours, minutes, seconds, milliseconds } = formattedRes;

useCreation

useMemouseRef 的封装加强版,可以替换这两个钩子。

  • useMemo 的值不一定是最新的值,但 useCreation 可以保证拿到的值一定是最新的值
  • 对于复杂常量的创建, useRef 容易出现潜在的的性能隐患,但 useCreation 可以避免

应用场景:需要拿到最新值、避免性能隐患时。

const nowData = useCreation(() => {}, []);

useEventListener

addEventListeneruseEffect, useRef 的封装。

应用场景:,监听各种事件。如:监听点击事件、键盘事件、滚动事件等。

useEventListener('click', () => setCount(v => v + 1), ref)

useHover

useStateuseEventListener 的封装。

应用场景:监听 DOM 元素是否有鼠标悬停。

const h = useHover(r, {
  onEnter: () => {
    console.log('onEnter');
  },
  onLeave: () => {
    console.log('onLeave');
  },
})

useInterval

setInterval 的封装。

应用场景:每隔一段时间,执行一次函数。

useInterval(() => {
  setN(n + 1);
}, 1000)

useLatest

useRef 的封装。

应用场景:随时确保获取的是最新值,并且没有闭包问题。

const fnRef = useLatest(fn)

useMount

useEffect 的封装。

应用场景:类似 componentDidMount 功能,组件渲染完成时。

useMount(() => {
  message.info('首次渲染')
});

usePow

useMemo 的封装。 useMemo (减少性能开销) 第一个参数是函数,第二个参数参数是可变的数组。

应用场景:低性能进行数字平方。

const data = usePow([1, 2, 3])