update-value
v1.0.2
Published
a small function can bind dom value and state
Downloads
2
Readme
How to use
A input or checkbox should have below properties and an onChange function.
name(required) value(required) type(optional)
onChange = (event, options) => {...}
options is and object, its properties:
state(required) callback val = event.target.value name = event.target.name type = event.target.type
the name property of the dom is the string path to find the value from the state, it can be 'data.name', and it will bind to this.state.data.name
eg1.
bind an input value to the this.state.data
<input name='data'
type="text"
onChange={(event) => updateValue(event, {state: this.state})}
value={this.state.data} />
eg2.
bind an input value to the this.state.data.name
<input name='data.name'
type="text"
onChange={(event) => updateValue(event, {state: this.state})}
value={this.state.data.name} />
eg3.
bind an input value to the this.state.data.name, and do some callback
<input name='data.name'
type="text"
onChange={(event) => updateValue(event, {state: this.state, callback: ()=> console.log('callback')})}
value={this.state.data.name} />