Should componentDidMount run from connectStateResults?

114 Views Asked by At

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>
    );
  }
1

There are 1 best solutions below

1
Bhojendra Rauniyar On

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.