Skip to content

Instantly share code, notes, and snippets.

@theKashey
Created April 15, 2018 10:40
Show Gist options
  • Save theKashey/c3114acaff041203e50e9a4912af0089 to your computer and use it in GitHub Desktop.
Save theKashey/c3114acaff041203e50e9a4912af0089 to your computer and use it in GitHub Desktop.
Table gDSFP
// base - https://github.com/reactjs/rfcs/pull/40#discussion_r180818891
import memoize from "lodash.memoize";
class Example {
getSortedData = memoize((list, sortFn) => list.slice().sort(sortFn))
getPagedData = memoize((list, page) => list.slice(page*10, (page+1)*10))
render() {
const sorted = this.getSortedData(this.props.data, this.props.sort);
const pages = this.getPagedData(sorted, this.props.page);
// Render with this.props, this.state, and derived values ...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment