react-controlled
higher-order-component for react controlled components
Installation
npm install --save react-controlled
Example
simple case
;; Component { const nickname = thispropsvalue; const age = thispropsvalue; } { return <div> <input type="text" ...thisprops/> <input type="text" ...thisprops/> <button onClick=thisonClickSave>save</button> </div>; } MyComponent
with defaultValue
It is recommanded to set default value at constructor.
;; Component { superprops; thisprops; } { return <div> <input type="text" ...thisprops/> </div>; } MyComponent
customize getValue function
default getValue function: args => args[0].target.value
;; Component { superprops; thisprops; } { return <div> <SomeComponent ...thisprops/> </div>; } MyComponent
getFieldValues, setFieldValues
;; Component { const values = thisprops; valuesnickname = 'my name is ' + valuesnickname; valuesage = 'my age is ' + valuesage; thisprops; } { return <div> <input type="text" ...thisprops/> <input type="text" ...thisprops/> <button onClick=thisonClick>example</button> </div>; } MyComponent