简体   繁体   中英

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.

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.

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM