Actually, there's something wrong in the way you set your dataSource
, in your constructor, you set it for the first time with: new ListView.DataSource({})
(this should not be changed later, because this is just kind of dummy thing, no data passed to it yet)
However, later you reset that state with : dataSource: this.state.dataSource.cloneWithRows(reservationData.previous)
=> (Here it has the cloneWithRows
, so it will have data now => which means the this.state.dataSource
"dummy-frame" itself has been changed, and the next execution of .cloneWithRows
will fail - will not have the .cloneWithRows
function anymore)
======> SOLUTION:
In my opinion, you can do:
In cardList.js:
// Put the data-source ds here, which won't be changed
var ds = new ListView.DataSource({rowHasChanged: (row1, row2) => row1 !== row2});
class CardList extends React.Component {
constructor(props) {
super(props);
this.state = {
reservationListStatus: this.props.reservationListStatus,
dataSource: ds.cloneWithRows(/* PUT YOUR INITIAL reservationData, OR JUST a blank array '[]' will be fine*/),
};
}
..and later on, you just need to use ds.cloneWithRows(YOUR_NEW_RESERVATION_DATA)
(always keep the ds
unchanged), something like this:
getReservationData() {
if ( this.props.reservationListStatus === "Previous Reservations" ) {
this.setState({
dataSource: ds.cloneWithRows(reservationData.previous)
})
} else {
this.setState({
dataSource: ds.cloneWithRows(reservationData.current)
})
}
console.log(this.state)
}
That is the way you should do, but if it doesn't work yet, please post here some errors you encounter, thanks