Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- counter;
- constructor(props) {
- super(props);
- this.state = {
- recommendation: [],
- progress: 0,
- };
- }
- componentDidMount() {
- const client = algoliasearch('applicationId', 'apiKey'),
- index = client.initIndex('indexName'),
- query = this.props.location.pathname.substring(1).replace(/[-_\/\\^$*+?.()|[\]{}]/g, ' ');
- index.search(query, (err, content) => {
- this.setState({
- recommendation: content.hits
- });
- });
- this.counter = setInterval(() => this.timer(), 20);
- }
- timer() {
- const progress = this.state.progress + 1;
- this.setState({
- progress,
- });
- if (progress >= 100) {
- clearInterval(this.counter);
- }
- }
Add Comment
Please, Sign In to add comment