@rcp/use.uncontrolled
v3.0.0
Published
Make props.value piped to state, and exposes `onChange`, make react component is **uncontrolled & controlled**
Downloads
36
Maintainers
Readme
@rcp/use.uncontrolled
Make props.value piped to state, and exposes onChange
, make react component is uncontrolled & controlled
Installation
npm install @rcp/use.uncontrolled
# or use yarn
yarn add @rcp/use.uncontrolled
Usage
import useUncontrolled from '@rcp/use.uncontrolled'
API
useUncontrolled
Parameters
value
{T} - Piped valuedefaultValue
{T} - Initialize value firstlyonChange
{(value: T) => void} - BindonChange
handler when value updatinguseEffect
{typeof React.useLayoutEffect}eq
{(a: T, b: T) => boolean}
Examples
function Input({ value, onChangeValue, defaultValue }) {
const [valueState, setValue] = useUncontrolled({ value, onChange: onChangeValue, defaultValue })
return <input type="text" value={valueState} onChange={(evt) => setValue(evt.target.value)} />
}
Returns Array [T, ((value: T) => T | T) => void]
Related
Authors
This library is written and maintained by imcuttle, [email protected].
License
MIT