LuisPinto
LuisPinto

Reputation: 1697

rowHasChanged Undefined is not a constructor

Hello I'm creating a grid and I have this constructor in my class

export class Grid extends Component {
    constructor (props) {
        super(props)
        var ds = new ListView.Datasource({rowHasChanged: (r1, r2) => r1 !== r2})
        this.state = {dataSource: ds.cloneWithRows(this._genRows({}))}
    }
.
.
.
}

I'm getting the following error when I try to run this:

Undefined is not a constructor (evaluating 'new) _reactNative.ListView.Datasource({rowHasChanged:function rowHasChanged(r1,r2){returnr1!==r2;}})')

Can someone give me a hand on this? Thank you in advance!

Upvotes: 2

Views: 1682

Answers (2)

shinzou
shinzou

Reputation: 6192

I had something similar happen to me and it took me a while to figure out this error so I'll write it out so other can use it.

What I had:

import foo from './foo'

class bar extends Component{
  constructor(props){
    super(props);
    const foo = new foo(); // getting foo is undefined and not a constructor
  }
}

So apparently in js that local assignment overwrites the outer one before the call to the constructor.

Upvotes: 0

Ivan Chernykh
Ivan Chernykh

Reputation: 42166

I think it is just a typo. Try using DataSource instead of Datasource in this line:

var ds = new ListView.DataSource( ... 

ListView reference: http://facebook.github.io/react-native/releases/0.29/docs/listview.html

Upvotes: 6

Related Questions