Guest User

Untitled

a guest
May 25th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. counter;
  2.  
  3. constructor(props) {
  4. super(props);
  5. this.state = {
  6. recommendation: [],
  7. progress: 0,
  8. };
  9. }
  10.  
  11. componentDidMount() {
  12. const client = algoliasearch('applicationId', 'apiKey'),
  13. index = client.initIndex('indexName'),
  14. query = this.props.location.pathname.substring(1).replace(/[-_\/\\^$*+?.()|[\]{}]/g, ' ');
  15. index.search(query, (err, content) => {
  16. this.setState({
  17. recommendation: content.hits
  18. });
  19. });
  20. this.counter = setInterval(() => this.timer(), 20);
  21. }
  22.  
  23. timer() {
  24. const progress = this.state.progress + 1;
  25. this.setState({
  26. progress,
  27. });
  28. if (progress >= 100) {
  29. clearInterval(this.counter);
  30. }
  31. }
Add Comment
Please, Sign In to add comment