I'm trying to create my own pagination (without using a package), but I can't get it to work.
I'm wondering if it has something to do with how I'm copying my arrays, but I'm not really sure.
class InsightSearchResults extends Component { state = { start: 0, end: 2, insightsArrayOriginal: [], copiedArr: [] } UNSAFE_componentWillReceiveProps(nextProps) { if (nextProps.insightList[0]) { this.setState({ insightsArrayOriginal: nextProps.insightList[0].insights, copiedArr: nextProps.insightList[0].insights.splice(this.state.start, this.state.end) }) } } clickNext = () => { let copied = [...this.state.insightsArrayOriginal]; this.setState({ start: this.state.start + 2, end: this.state.end + 2 }, () => { this.setState({ copiedArr: copied.splice(this.state.start, this.state.end) }) }) } clickPrev = () => { this.setState({ start: this.state.start - 2 < 0 ? 0 : this.state.start - 2, end: this.state.end - 2 }) } render() { const { copiedArr } = this.state; return ( <div style={{padding: "1.5rem"}}> {copiedArr ? copiedArr.map(insight => ( <div> <Grid className="insight_result_block"> <Col className="insight_results_col2" span="10"> <div> <h4>Hello</h4> <p>{insight.insightDesc}</p> </div> </Col> </Grid> <hr className="bottom_hr_insight" /> </div> )) : <p>loading...</p> } <button onClick={this.clickPrev}>Prev</button> <button onClick={this.clickNext}>Next</button> </div> ) } } I haven't really worked on the "prev" part yet. I'm just trying to get the "next" to work for now...