shouldComponentUpdate is not never called

Kis*_*ori 5 reactjs

Please have a look at my code. I try to limit re-render of given stateless component but doing this found that shouldComponentUpdate is never called. I have removed wrapper from styledComponents (what was reported to be a case for someone before) but still is definitely not called. Besides all, one could write an article on catches of this functions

import React from 'react';
import GoogleSearchForm from './RenderGoogleSearchForm.js';
import ButtonWithMessage from './ButtonWithMessage.js';
import styled from 'styled-components';

export default class RenderTableOverHead extends React.Component{

  constructor(props) {
    super(props);
  }

  shouldComponentUpdate(nextProps, nextState) {
    console.log('shoulItdUpdate');
    return false;
  }

  render(){
    console.log('render overhead');
    const wrapstyle = 'd-flex align-items-center justify-content-center border-none'

  const Button = {
    // lots of defined buttons
  }

  return(

    <div className = {wrapstyle}> 
      {!this.props.isHiddenReturnButton && <Button.ReturnToPreliminarySearch />}
      {!this.props.isHiddenWelcomeButton && <Button.Welcome />}
      {!this.props.isHiddenFailureMsg && <Button.SearchFailure />}
      {!this.props.isHiddenResultsMsg && <Button.SearchResults /> }
      {(this.props.isConnectionOK >0||this.props.isConnectionOK===undefined) && <Button.ConnectionError /> }
      {!this.props.isHiddenInputForm && <GoogleSearchForm  FetchBooks = {this.props.FetchBooks} /> }
      {!this.props.isHiddenFilterToggleButton && <Button.FilterShowPrompt />}
  </div>
)}}
Run Code Online (Sandbox Code Playgroud)

As requested - that is called by parent like this:

import RenderTableOverHead from './components/RenderTableOverHead.js';
Run Code Online (Sandbox Code Playgroud)

below it is packed with its props to form new function

  const Overhead = ()=>{return(  

      <RenderTableOverHead 

      isHiddenInputForm={ this.state.isHiddenInputForm}
      isHiddenWelcomeButton={this.state.isHiddenWelcomeButton}
      ShowGoogleSearch={this.handleWelcomeButtonClick}
      //SubmitInputDataToParentState={this.fetchBooks}
      FetchBooks ={this.fetchBooks}
      isHiddenResultsMsg={this.state.isHiddenResultsMsg}
      isHiddenFailureMsg={this.state.isHiddenFailureMsg}
      toggleFilterVisibility={this.toggleFilterVisibility}
      numberOfResults ={catalog.TotalNumberOfBooks}
      numberOfPages =/*{_.last(TableWithPageNumbers)}*/{catalog.NumberOfPages}
      currentPageNumber ={catalog.CurrentPageNumber}
      //currentPage ={this.Page}//tu podmieniony numer strony jest kosztem powy?szego
      isConnectionOK={this.state.connectionStatus}
      //errorStatus ={this.state.errorStatus}
      //errorMessage ={this.state.errorMessage}
      //handleError={this.handleError}
      isHiddenReturnButton={this.state.isHiddenReturnButton}
      isHiddenFilterToggleButton={this.state.isHiddenFilterToggleButton}
      />


);}
Run Code Online (Sandbox Code Playgroud)

and is returned like that (here its named Overhead)

return(

        <div className='container'>
        <Overhead />
        <Pagination />
        {isDataLoaded && 
           <div className = {cardStyle}>
           <table className = {tableStyle}>
                <thead className = {tableHeaderStyle}>
                <Headline />     
                {Filtration}            
                </thead>
                <TableBody />     
       </table>
       </div>};
       </div>)
Run Code Online (Sandbox Code Playgroud)

flq*_*flq 0

我\xe2\x80\x98ll 会尝试一下,因为我\xe2\x80\x99m 不确定问题是什么,但这里有一些我看到的东西对我来说似乎不惯用,并且可能会以某种方式做出反应。

\n\n
    \n
  • 首先,查看生命周期方法的官方文档:它指出即使 sCU 返回 false,在某些条件下也可能会发生重新渲染
  • \n
  • \xe2\x80\x9elots 定义的按钮\xe2\x80\x9c 看起来非常可疑,因为它是一个性能消耗者。看起来你\xe2\x80\x99正在每个渲染上重建一堆组件。这很可能是静态信息,可以保存在其他地方。
  • \n
  • 将实际组件包装到另一个 lambda 中,然后关闭外部状态,然后将其用作反应组件,看起来非常可疑RenderTableOverhead简化该代码,例如直接在正确的位置使用。另外,不要\xe2\x80\x99t 调用组件本身RenderSomething ...将其更多地视为一段 UI 的声明。
  • \n
\n\n

我希望这有帮助。

\n