List View
class Pokedex extends Component {
constructor(props) {
super(props);
//Define a ListView.DataSource. DataSource requires you to define a rowHasChanged, comparator, and we'll use Immutable.is here for that.
const dataSource = new ListView.DataSource({
rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
});
//Don't forget to add your dataSource to the state.
this.state = { pokemon: dataSource };
}
componentWillReceiveProps({ pokemon }) {
this.setState({
pokemon: this.state.pokemon.cloneWithRows(pokemon.toArray()),
});
}
render() {
const { pokemon } = this.state;
const { goToPokemonDetail, ready } = this.props;
return (
<View style={ styles.container }>
<ListView dataSource={ pokemon }
style={ styles.listView }
renderRow={ (...args) => renderRow(goToPokemonDetail, ...args) }
enableEmptySections />
<SearchBar onChange={ filter } value={ query } />
<KeyboardSpacer />
</View>
);
}
}Last updated
Was this helpful?