user2985523
user2985523

Reputation: 27

Cannot read proprety "dataSource" of null

I feel like this should be pretty straightforward but I'm losing my mind trying to create a basic list in react. I tried the minimalistic sample code on react-native but it yields the error message. Cannot read property "dataSource" of null, even thought the dataSource is being created in the getInitialState.

Here it is

Image

Upvotes: 0

Views: 1922

Answers (1)

alvaromb
alvaromb

Reputation: 4856

Use this instead of getInitialState:

constructor (props) {
  super(props);
  var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
  this.state = {
    dataSource: ds.cloneWithRows(['row1', 'row2'])
  };
}

This is because you're using ES2016 classes: http://facebook.github.io/react/docs/reusable-components.html#es6-classes

Upvotes: 3

Related Questions