Hello, I am newbie and start learning Android mobile programming using react native.. I encounter a problem using setState state, it's keep show an error : "Can't find variable : setState"

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
} from 'react-native';

export default class WeatherProject extends Component {
  constructor(props) {
    super (props)
    this.state={appendText:'crazy!'};
  }
  render () {
    return (
      <View> <Text onPress={() => setState({text: ' Native'})}>{this.
          props.setState +" "+ this.state.appendText}</Text> </View>
);
}
}

AppRegistry.registerComponent('WeatherProject', () => WeatherProject);

Could someone pointed where is the problem in the code?

Re: setState error when onPress Text component 80 80

use this.setState() instead of setState().
Never use setState() directly without this.

Ex. this.setState({ text :'Native' })

Re: setState error when onPress Text component 80 80

use this.setState() instead of setState().

commented: This just repeats an earlier answer -3
Re: setState error when onPress Text component 80 80

What language do you use?

Re: setState error when onPress Text component 80 80

You can't use setState() as it doesn't make sence in your case, you have to add "this." beforehand.
Have a look at the documentation:
https://reactjs.org/docs/react-component.html

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.