case 'splitWord':
if(this.props.remedStatus){
console.log(this.props.remedStatus)
console.log("remed")
return(
<HotspotRemed
xml={this.receivedXML}
userXml={this.usersAnswerXML}
correctAnswer ={this.ansString}
type={this.splitType}
/>
)
} else {
console.log("reurn word")
return(
<div style ={wrap_style} >
{this.forceUpdate}
<SplitXMLPreview xml={this.receivedXML}
type='w'
assignedSplitContentClick={(contentId, selectionType) => {
this.handleSplitContentClick(contentId, selectionType, 'w')
}}
getCorrectAns={(answers) => {
this.correctAnswers = answers
}}
/>
</div>
)
}
break
<<<==NOW HERE IS MY RENDER MEHTOD.==>>>
render() {
console.log("render")
return (
<div className="previewtemplate" style ={template}>
{this.templateArea(this.state.templateType)}
</div>
);
}
}
我只是想知道如何停止重新渲染组件。
我有三个按钮,当我单击一个按钮时,它会执行该操作。
只有一个按钮。其中我使用 if else 当我单击该按钮时它返回 false 和组件 false 调用,这很好工作,当再次单击该按钮时它调用 true 组件,这对我来说也很棒,但是当我再次单击按钮时首先它调用渲染然后调用我的组件。我不想调用渲染它调用我的组件。
我读了一些博客,他们建议使用 this.forceupdate。 我该怎么办?帮帮我。
最佳答案
您可以实现自定义逻辑,以确定组件是否应使用 shouldComponentUpdate
方法更新(重新渲染)。
例如:
shouldComponentUpdate () {
return false // this will lead to never re-render the component
}
Note that in the future React may treat shouldComponentUpdate() as a hint rather than a strict directive, and returning false may still result in a re-rendering of the component.
关于javascript - 如何在reactjs中停止重新渲染?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48710062/