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)
我\xe2\x80\x98ll 会尝试一下,因为我\xe2\x80\x99m 不确定问题是什么,但这里有一些我看到的东西对我来说似乎不惯用,并且可能会以某种方式做出反应。
\n\nRenderTableOverhead简化该代码,例如直接在正确的位置使用。另外,不要\xe2\x80\x99t 调用组件本身RenderSomething ...将其更多地视为一段 UI 的声明。我希望这有帮助。
\n| 归档时间: |
|
| 查看次数: |
3216 次 |
| 最近记录: |