React Native render function gives an error : Unexpected token

- 1 answer

Ad

I am trying out a basic example to work on AsyncStorage on react native. When I try to run the application, it throws an error at the render function.

Here is my code-

var AsyncStorageExample = React.createClass({

    getInitialState: function () {
        return {
            arr : [],
        }
    },

    stateSetting: function(arrval) {
        this.setState({
            arr : arrval,
    },

    render : function() {
    return (
      <View>
        {this.state.arr.map(arr =>
          <Text key={arr.name}>
            &bull; {arr.name}
          </Text>
        )};
      </View>
    );
  },

});

Error is thrown at the : of render function render : function(){Unexpected token is what I get on the red screen.

What am I doing wrong here?

Ad

Answer

Ad

this

this.setState({
            arr : arrval,

should be

this.setState({
            arr : arrval,
})
Ad
source: stackoverflow.com
Ad