0.1.0 • Published 12 months ago

@jelper/use-value v0.1.0

Weekly downloads
-
License
ISC
Repository
-
Last release
12 months ago

@jelper/useValue

reack受控组件hook, useValue受控传入value

使用

import useValue from '@jelper/use-value'

function Demo() {
  const [outValue, setOutValue] = useState('')
  const [value, setValue] = useValue(outValue)
  return (
    <>
      <input value={value} onInput={(ev) => setValue(ev.target.value)} />
      <button onClick={() => setOutValue('')} >清空</button>
    </>
  )
}

API

// 配置
interface Options<T> {
  // 判断 传入value是否变更,默认 ===
  isEqual?: (a:T, b: T) => boolean
}
type SetValue<T> = (v: T|((oldVal: T) => T)) => void

type UseValue<T = any> = (val: T, opts: Options<T>) => [T, SetValue<T>];
0.1.0

12 months ago

0.0.2

1 year ago

0.0.1

1 year ago