0

I'm trying to create an infinite siema carousel using algolia's instantsearch in react, but I don't think the connectors behave like React components. Should I expect componentDidMount to be called here? Suggestions? Ideas?

class ActorsClass extends connectStateResults {

  constructor(props){
    super(props);
    var { searchState, searchResults } = props;
    this.hasResults = searchResults && searchResults.nbHits !== 0;
  }

  componentDidMount() {
    console.log("componentDidMount " + this.props.siema)
    this.siema = new Siema(this.props.siema);
  }

  prev = () => {
    this.siema.prev()
  };

  next = () => {
    this.siema.next()
  };

  render = () => {
    return (
        <div className="actors-container">
          <div xhidden={!this.hasResults}>
            <h1>Actors</h1>
            <InfiniteHits hitComponent={HitActors} />
          </div>
        <button onClick={this.prev}>Prev</button>
        <button onClick={this.next}>Next</button>
      </div>
    );
  }
chad steele
  • 828
  • 9
  • 13

1 Answers1

0

Whenever the connected component receives new props they are re-invoked. It means you can use componentDidUpdate hook for your use case.

You may be interested to use reselect. See the docs for using selector.

Bhojendra Rauniyar
  • 83,432
  • 35
  • 168
  • 231
  • Thank you. I've tried componentDidUpdate as well - no success. I'm not certain that the Algolia connector components call either or follow the usual React lifecycle. – chad steele Sep 04 '18 at 14:48