[英]React Hooks - Best way to remove an component temporarily from DOM without unmounting it
I'm currently doing this with a combination of the React.memo
HOC and display: none
to minimize performance impact on the render.我目前正在结合使用React.memo
HOC 和display: none
以尽量减少对渲染的性能影响。
I would like to know if there's a way that impact less on the performance, since I can have multiple components on this invisible state on the screen.我想知道是否有一种对性能影响较小的方法,因为我可以在屏幕上这个不可见的 state 上有多个组件。
Try this尝试这个
el.hide = () => {
el.storeInnerHTML = el.innerHTML //create property
el.innerHTML = '' //done
}
el.show = () => {
if((el.storeInnerHTML ?? true) === true) return
el.innerHTML = el.storeInnerHTML
delete el.storeInnerHTML
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.