2

I am working on pagination . We have two buttons in application Next and Prev. I am showing 5 records on each page , I want to disabled Next Button if currently we have no data in array ( array data is coming from API ) to display . I am beginner to ReactJS , Somebody please help me how I can disabled next button .

Code

        class Example extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      Item: 5,
      skip: 0
    }

    this.handleClick = this.handleClick.bind(this);
  }

  urlParams() {
    return `http://localhost:3001/meetups?filter[limit]=${(this.state.Item)}&&filter[skip]=${this.state.skip}`
  }

  handleClick() {
    this.setState({skip: this.state.skip + 1})
  }

  render() {
    return (
      <div>
        <a href={this.urlParams()}>Example link</a>
        <pre>{this.urlParams()}</pre>
        <button onClick={this.handleClick}>Change link</button>
      </div>
    )
  }
}


ReactDOM.render(<Example/>, document.querySelector('div#my-example' ))
Jon
  • 293
  • 3
  • 11
  • 29

1 Answers1

3

I think actually you need to reference the length of allData. Otherwise how do you know if you have hit the limit?

<Button positive onClick={this.btnClick} 
  disabled={this.state.skip >= this.state.allData.length} >Next</Button>
jsdeveloper
  • 3,945
  • 1
  • 15
  • 14
  • Can you please answer this question ? Thanks https://stackoverflow.com/questions/55170713/react-how-to-show-message-if-there-is-no-records – Jon Mar 14 '19 at 19:39