- import React from 'react';
- class TextboxInputView extends React.Component {
- constructor(props) {
- super(props);
- this.state = {
- value: ''
- }
- }
- onValueChanged(e) {
- var newValue = e.target.value;
- this.setState({ value: newValue });
- if (this.props.valueChanged != null)
- this.props.valueChanged(newValue);
- }
- render() {
- var unitsCheck = "";
- if (this.props.data.Unit != "") { unitsCheck = "Units" className='col-md-4' Style='font-weight:normal' readOnly type="text" value={this.props.data.Unit} /> }
- return this.props.Id}>;
- "text" className='col-md-6' value={this.state.value} onChange={(e) => this.onValueChanged(e)} /> {this.props.Name}
- {unitsCheck}
- }
- getDefaultValue() {
- var defaultValue = null;
- if (this.props.defaultValues != null && this.props.defaultValues.length === 1 && this.props.defaultValues[0] !== '')
- defaultValue = this.props.defaultValues[0];
- return defaultValue;
- }
- componentDidMount() {
- var defaultValue = this.getDefaultValue();
- if (defaultValue != null && this.state.value !== defaultValue) {
- this.onValueChanged({ target: { value: defaultValue } });
- }
- }
- componentWillReceiveProps(nextProps) {
- if (this.props !== nextProps && nextProps.isResetValues) {
- let defaultValue = this.getDefaultValue();
- defaultValue = defaultValue === null ? '' : defaultValue;
- if (this.state.value !== defaultValue) {
- this.onValueChanged({ target: { value: defaultValue } });
- }
- }
- }
- }
- export default TextboxInputView
Type Error:Cannot read property of Unit undefined
Hi have added a new text box under the render which is Units and it works fine in local machine but throws error in server built . Does it has to be mounted with the component . Am new to reactjs could some one suggest .
Bhairab DuttPosted Jun 29, 2018, 1:22 PM
In your code "this.props.data.Unit" , props.data must has the property of Unit so first you can check the property Unit its declared with in props.data or not . If its defined the error will resolved.
Hope Its help you .Please accept the ans if its helps to you.
Thanks