Reactjs componentDidMount应该从connectStateResults运行吗?
我试图使用algolia创建一个无限旋转木马,但我认为连接器的行为不像React组件。我应该在这里调用componentDidMount吗?建议?想法Reactjs componentDidMount应该从connectStateResults运行吗?,reactjs,algolia,infinite-carousel,instantsearch,Reactjs,Algolia,Infinite Carousel,Instantsearch,我试图使用algolia创建一个无限旋转木马,但我认为连接器的行为不像React组件。我应该在这里调用componentDidMount吗?建议?想法 class ActorsClass extends connectStateResults { constructor(props){ super(props); var { searchState, searchResults } = props; this.hasResults = searchResults &
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>
);
}
class ActorClass扩展了connectStateResults{
建造师(道具){
超级(道具);
var{searchState,searchResults}=props;
this.hasResults=searchResults&&searchResults.nbHits!==0;
}
componentDidMount(){
log(“componentDidMount”+this.props.siema)
this.siema=新的siema(this.props.siema);
}
上一页=()=>{
this.siema.prev()
};
下一步=()=>{
this.siema.next()
};
渲染=()=>{
返回(
演员
上
下一个
);
}
只要连接的组件收到新的道具,它们就会被重新调用。这意味着您可以为您的用例使用componentdiddupdate
hook
您可能有兴趣使用。请参阅用于使用选择器的。谢谢。我也尝试了componentDidUpdate-没有成功。我不确定Algolia连接器组件是否调用或遵循通常的React生命周期。