Answer the question
In order to leave comments, you need to log in
Redux - how to store data in input when rendering?
There is a form in the application
It serves to add and edit
When data about editing comes from dispatch, the fields must be filled with data
What problems:
Fields are filled but do not change (value='.{..}')
Fields are filled when you edit and render but new after dispatch, the data is pushed back (via componentDidUpdate)
The fields are filled and changed and store the edited data, BUT with a shift by 1 previous value (via componentDidUpdate + I store it via onChange in this.feilds={...})
defaultValue - does not help, since the form is dynamic
constructor(props) {
super(props);
this.fields = {}
}
onChangeName(e) {
this.fields.tableName_input = e.target.value
}
onChangeParticipants(e) {
this.fields.tableParticipants_select = e.target.value
}
componentDidUpdate(params){
if (params.editing){
console.log(params)
let tableName_input = this.fields.tableName_input && this.fields.tableName_input || params.table.name
ReactDOM.findDOMNode(this.refs.tableName_input).value = tableName_input
let tableParticipants_select = this.fields.tableParticipants_select && this.fields.tableParticipants_select || params.table.participants
ReactDOM.findDOMNode(this.refs.tableParticipants_select).value = tableParticipants_select
}
}
Answer the question
In order to leave comments, you need to log in
import React, { Component, PropTypes } from 'react'
class Main extends Component {
constructor(props, context) {
super(props, context);
this.state = {
inputValue: this.props.inputValue || ''
};
}
handleNameChange(e) {
this.setState({ inputValue: e.target.value });
}
render() {
return (
<div>
<input type='text' onChange={ ::this.handleInputChange } />
<div>input value: { this.state.inputValue }</div>
</div>
)
}
}
export default Main
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question