React : How to display Error if no record match

2019-08-21 08:38发布

问题:

I am working on React Project . Actually , I implemented search filter but I have some problem regarding search filter . I want to show message if there is no match record found but currently when I type something if record found it showed to the user but when I type something which are not matched it not show error message instead it showing existing record . I want to set error message if record found then show record if record is not found show error message instead of showing existing all record . I will also provide GIF File where I am doing this stuff practical. Could someone please help me how to fix this problem . Thanks

Sorry , If I made mistake in English Grammar . I am not native Speaker

GIF File

Full Component 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' ))