Skip to content

Instantly share code, notes, and snippets.

@kmagiera
Created July 24, 2018 14:02
Show Gist options
  • Save kmagiera/414e4c91033248facd9ea1f62d7978c2 to your computer and use it in GitHub Desktop.
Save kmagiera/414e4c91033248facd9ea1f62d7978c2 to your computer and use it in GitHub Desktop.
class NamesList extends React.PureComponent {
static getDerivedStateFromProps(nextProps, prevState) {
const letters = extractLetters(nextProps.data);
return {
sections: letters.map(letter => {
const data = nextProps.data.filter(item => item.startsWith(letter));
return {
letter,
data,
renderItem: ({ item }) => (
<Item color={nextProps.color} name={item} />
),
};
}),
};
}
render() {
return (
<SectionList
sections={this.state.sections}
renderSectionHeader={({ section }) => <Header section={section} />}
/>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment