Package Exports
- use-merge-value
- use-merge-value/dist/index.esm.js
- use-merge-value/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (use-merge-value) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
use-merge-value
Easier to write a controlled component
此 hooks 可以轻松的实现一个受控组件。使用方式类似于 useState ,支持通过第二个参数传入 { value, onChange} 来覆盖掉默认的 value 与 setValue。
Usage
yarn add use-merge-valueimport React, { useState } from 'react';
import useMergeState from 'use-merge-value';
const ControlledInput: React.FC<{ value: string; onChange: (value: string) => void }> = props => {
const [value, setValue] = useMergeState('', props);
return (
<div>
<input value={value} onChange={e => setValue(e.target.value)}></input>{' '}
</div>
);
};LICENSE
MIT