Dipen Bhagat
Dipen Bhagat

Reputation: 29

Error: Object are not valid as a react child?

export default class App extends Component<Props> {
constructor() {
    super();
    this.state = {
        value: "Edit me!"
    };
    this.handleChangeText = this.handleChangeText.bind(this);


}

handleChangeText(newText) {
    this.setState({
        value: newText
    });
}


render() {
    return (
        <View style={styles.container}>
            <TextInput style={styles.editText}
                       onChange={this.handleChangeText}/>
            <Text>hello {this.state.value}</Text>
        </View>
    );
}

I am new to react native. I am getting error on hello {this.state.value} line. How can i solve this. Please help me

Upvotes: 1

Views: 64

Answers (1)

mosabbir tuhin
mosabbir tuhin

Reputation: 625

Can you try this?

export default class App extends Component<Props> {
  constructor(Props) {
      super(props);
      this.state = {
        value: "Edit me!"
      };
  }
  handleChangeText = (newText) => {
      this.setState({
          value: newText
      });
  }
  render() {
      return (
          <View style={styles.container}>
              <TextInput
                style={styles.editText}
                onChangeText={this.handleChangeText}
                />
              <Text>hello {this.state.value}</Text>
          </View>
      );
  }
}

Upvotes: 2

Related Questions