Code:
import React, { Component } from 'react';
import { Button, Input, Row, Col, Label } from 'reactstrap';
export default class Settings extends Component {
constructor(props) {
super(props);
this.state = {
tallyPort: '', companyYear: '', interval: '', timeRange: '',
databasePort: '', databaseUserName: '', databasePassword: ''
};
}
handleChange = (stateName, e) => {
this.setState({ stateName: e.target.value });
}
handleSave = () => {
console.log(this.state)
}
render() {
return(
<div className="dashboard" >
<Input name="tallyPort" onChange={this.handleChange.bind(this, 'tallyPort')} />
<Input name="companyYear" onChange={this.handleChange.bind(this, 'companyYear')} />
<Input name="interval" onChange={this.handleChange.bind(this, 'companyYear')} />
<Input name="timeRange" onChange={this.handleChange.bind(this, 'companyYear')} />
<Input name="databasePort" onChange={this.handleChange.bind(this, 'companyYear')} />
<Input name="databaseUserName" onChange={this.handleChange.bind(this, 'companyYear')} />
<Input name="databasePassword" onChange={this.handleChange.bind(this, 'companyYear')} />
<Button style={{ width: '200px', marginLeft: '720px'}} onClick={this.handleSave.bind(this)} color="primary">Save</Button>
</div>
);
}
}
Main problem with this.setState function, I'm not understand why it is not working.
I'm trying to set each state value on "onChange" of input field, "setState" is not working properly, when i'm console all states after given values, it returns blank values, any one help me?