I got this code from react bootstrap website https://react-bootstrap.github.io/components/forms/ I will like to know the use of the following in the code
- this.handleChange = this.handleChange.bind(this)
- The use of making the
value
inthis.state = { value: '' }; }
empty - The use of setting the
validationState
attribute invalidationState={this.getValidationState()}
And the use of setting two renders, why not just one render and is it possible to set more than one render
class FormExample extends React.Component { constructor(props, context) { super(props, context); this.handleChange = this.handleChange.bind(this); this.state = { value: '' }; } getValidationState() { const length = this.state.value.length; if (length > 10) return 'success'; else if (length > 5) return 'warning'; else if (length > 0) return 'error'; return null; } handleChange(e) { this.setState({ value: e.target.value }); } render() { return ( <form> <FormGroup controlId="formBasicText" validationState={this.getValidationState()} > <ControlLabel>Working example with validation</ControlLabel> <FormControl type="text" value={this.state.value} placeholder="Enter text" onChange={this.handleChange} /> <FormControl.Feedback /> <HelpBlock>Validation is based on string length.</HelpBlock> </FormGroup> </form> ); } } render(<FormExample />);