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

@aligov/hooks

v1.3.5

Published

hooks

Downloads

56

Readme

hooks

@aligov/hooks

hooks

API

useAction

主要用于辅助 dialog 的新建、编辑和查看等操作,提供判断是创建、编辑还是查看的模式判断,以及对应的对象数据。

const {
    payload,
    setPayload,
    isCreate,
    isEdit,
    isView,
    doCreate,
    doEdit,
    doView,
    reset,
} = useAction(optionalInitPayload);
  • payload:当前操作对应的数据,可以通过 optionalInitPayloadsetPayload(newPaylod) 来指定
  • setPayload(newPayload):指定新操作对象,比如编辑表格行时,传入行 record
  • isCreatedoCreate() 对应,当调用 doCreate() 后,isCreate 是 true。isEditdoEdit() 以及 isViewdoView() 同理
  • reset() 目前只重置 view、edit、create 这些 action,不重置 payload。如果需要,显示调用 setPayload

useUpdate

ahooks 中的 useUpdate 类似,主要目的是提供一个方法,触发组件内部的重新渲染,也可用于给别的 hooks 提供重新运行的能力。

const { _, delayBeforeUpdate, update } = useUpdate();

  • _,一个随机数,一般不用关注它,除非做为依赖使用
  • update(optionalDelay):触发更新,可指定触发前的延时,单位:ms
  • delayBeforeUpdate:boolean,true 表示还在等待 delay 结束。

useSimpleQuery

用于简单的异步接口查询 hooks,支持指定初始值、请求函数、请求参数、返回结果、请求状态以及重新请求的能力。

const {
    pending,
    done,
    failed,
    finish,
    data,
    reload
} = useSimpleQuery(initValue, queryFn, queryFnArg1, queryFnArg2, ...);
  • pending:boolean,请求中
  • done:boolean,请求成功
  • failed:boolean,请求失败
  • finish:boolean,请求完成(成功或失败)
  • data:any, 请求返回的数据
  • reload(optionalDelay):重新请求

系列 hook 包括:

  • useConditionalSimpleQuery(shouldRequest, initValue, queryFn, ...args)useSimpleQuery 的条件化版本,shouldRequest 为 true 时才查询,用于符合特定条件才能请求的场景。
  • useSimpleListQuery(initValue, queryFn, ...args),适配通用列表查询接口数据结构规范的 hook
  • useConditionalSimpleListQuery(shouldRequest, initValue, queryFn, ...args)useSimpleListQuery 的条件化版本

listQuery reload

特别地,useSimpleListQueryuseConditionalSimpleListQueryreload 方法和 simpleQueryreload 方法有所区别。

  • reload(delay)simpleQuery 的一致
  • reload({ delay, deleteCount })
    • deleteCount:可选,如果有,并且 delete 后,页码发生了变更,那么会加载新页码的数据,并且忽略 delay 属性;否则和 simpleQuery 的 reload 行为一致。
    • delay:可选,没有 deleteCount 或者有 deleteCount 但页码不变的情况下,和 simpleQuery 的 reload 行为一致,如果有设置 delay,那么将延迟刷新。