@kne/use-control-value

0.1.8 • Public • Published

useControlValue

实现了同时支持受控和非受控组件状态管理的hooks

npm i @kne/use-control-value

使用说明

import useControlValue from '@kne/use-control-value';

const SomeComponent = (props)=>{
  const [value,setValue] = useControlValue(props);
  return (
    <input type="text" value={value} onChange={(e)=>{
      setValue(e.target.value);
    }}/> 
  );
};

上述例子中创建的组件SomeComponent,当给他传入defaultValue时表现为一个非受控组件,给他传value时表现为一个受控组件

Readme

Keywords

Package Sidebar

Install

npm i @kne/use-control-value

Weekly Downloads

1

Version

0.1.8

License

ISC

Unpacked Size

33.3 kB

Total Files

11

Last publish

Collaborators

  • metacoo
  • yangwang123456
  • juliewang
  • lingtong