3

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' ))
1
  • 1
    <Button positive onClick={this.btnClick} disabled={this.state.Item==='' || this.state.data.length === 0} >Next</Button> ? Commented Mar 14, 2019 at 18:19

1 Answer 1

4

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>
Sign up to request clarification or add additional context in comments.

1 Comment

Can you please answer this question ? Thanks stackoverflow.com/questions/55170713/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.