MCPcopy Create free account
hub / github.com/Autodesk/react-base-table / App

Class App

website/src/examples/infinite-loading.js:85–187  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83`
84
85export default class App extends React.Component {
86 state = {
87 data: [],
88 loading: true,
89 loadingMore: false,
90 loadedAll: false,
91 }
92
93 fetchData(offset = 0, limit = PAGE_SIZE) {
94 return delay(3000).then(() => {
95 return DATA.slice(offset, offset + limit)
96 })
97 }
98
99 loadData() {
100 this.fetchData(0, Math.random() < 0.2 ? 0 : PAGE_SIZE).then(data => {
101 if (!this._isMount) return
102 this.setState({
103 data,
104 loading: false,
105 loadedAll: data.length < PAGE_SIZE,
106 })
107 })
108 }
109
110 loadMore() {
111 this.setState({ loadingMore: true })
112 this.fetchData(this.state.data.length).then(data => {
113 if (!this._isMount) return
114 this.setState({
115 data: [...this.state.data, ...data],
116 loadingMore: false,
117 loadedAll: data.length < PAGE_SIZE,
118 })
119 })
120 }
121
122 handleEndReached = args => {
123 action('onEndReached')(args)
124 const { loading, loadingMore, loadedAll } = this.state
125 if (loading || loadingMore || loadedAll) return
126 this.loadMore()
127 }
128
129 handleReload = () => {
130 this.setState({
131 data: [],
132 loading: true,
133 })
134 this.loadData()
135 }
136
137 renderEmpty = () => {
138 if (this.state.loading) return null
139 return <Empty>No data available</Empty>
140 }
141
142 renderOverlay = () => {

Callers

nothing calls this directly

Calls 5

loadMoreMethod · 0.95
loadDataMethod · 0.95
actionFunction · 0.85
renderFunction · 0.85
componentWillUnmountFunction · 0.50

Tested by

no test coverage detected