Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@jdfed/hooks

Package Overview
Dependencies
Maintainers
5
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jdfed/hooks

drip-form通用hooks

  • 0.8.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
5
Created
Source

@jdfed/hooks

babelform 通用 hooks

useClickOne

  • 控制按钮只能点击一次
Usage
import React, { useState } form 'react
import { useClickOne } from '@jdfed/hooks'
import { Button } from 'antd'

const Demo = () => {

  const _setCount = useClickOne(() => {
    /*
    * 做些操作
    */
  }, [])

  return (
    <>
      <Button onCLick={_setCount}></Button>
    </>
  )
}

useEventCallback

  • 重写 useCallback(保证函数即使 dependencies 依赖改变。也不会重新生成) 解决因为 useCallback 的依赖频繁变化导致 useCallback 缓存效果很差甚至影响性能的问题 fn 函数 dependencies 依赖数组
Usage
import React, { useState } form 'react
import { useEventCallback, useField } from '@jdfed/hooks'
import { Button } from 'antd'

const Demo = (fieldData) => {
  const [initValue, setValue] = useState(fieldData)
  const _onChange = useField(
    { fieldKey, onChange, options: { isUploader: true } },
    dispatch
  )
  change = useEventCallback(() => {
    (value) => {
      setValue(value)
    }
  }, [_onChange])
  return (
    <>
      <Input onChange={change} />
    </>
  )
}

useField

  • 将表单数据保存为不可变数据
Usage
useField({ fieldKey , onChange , options })

useModal

  • 设置 modal 的展示隐藏
Usage
import React, { useState } form 'react
import { useModal } from '@jdfed/hooks'
import { Modal } from 'antd'

const Demo = () => {
  const [defaultStatus] = useState(false)
  const [visible] = useModal(defaultStatus)
  return (
    <>
      <Modal visible=(visible)/>
    </>
  )
}

usePrevious

  • 返回上一次的 value 值
Usage
import React, { useState } form 'react
import { usePrevious } from '@jdfed/hooks'

const Demo = () => {
  const [defaultStatus] = useState(false)
  //上一次value的值
  const preValue = usePrevious(defaultValue)
  return (
    <div>{value}</div>
  )
}

useQuery

  • 查询表单数据
Usage
cosnt queryOptionsFuc = useQuery({}, dispatch)

useRefProp

  • 当 callback 依赖过多时,使用 useRefProp 防止 onCLick 事件多次生成
Usage
import {useRefProp} from 'hooks/index'
      const MyComponent = ()=> {
        const ref = useRefProp()
        const onClick = useRefProp(()=>{ const {a,b,c,d}=ref.current click事件 },[])
        return <div onClick={onClick}>
      }

useValidate

  • 实时校验表单数据
Usage
const validate = () => {
  ......
  ......
  return {
    pass,
    errors,
    errorsMap,
    formData: newFormData,
  }
}

const validateDebounce = useValidate(validate)

Keywords

FAQs

Package last updated on 15 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc