import { h, Component } from 'preact';

import Result from './Result';
import store from '../store';

export default class ResultList extends Component {
  componentDidMount() {
    this.unsubscribe = store.subscribe(() => this.forceUpdate());
  }

  componentWillUnmount() {
    this.unsubscribe();
  }

  render() {
    const { results } = store.getState();
    console.log(results);

    return (
      <ul>{results && results.map((result, i) => <Result key={i} {...result} />)}</ul>
    );
  }
}

