46
Skip unnecessary rerendering with render props.
source link: https://www.tuicool.com/articles/hit/6Ffeayn
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
EnabledUpdateIf
Skip unnecessary rerendering with render props.
Why?
shouldComponentUpdate
in each components is hard to maintain. <EnabledUpdateIf />
makes more obvious and readable when the component is able to update or not.
Install
$ npm i enabled-update-if
Usage
import React from 'react' import EnabledUpdateIf from 'enabled-update-if' return ( <App> <EnabledUpdateIf condition={ this.state.isModalHidden }> { () => ( <MainContent>...</MainContent> ) } </EnabledUpdateIf> <Modal isHidden={ this.state.isModalHidden } /> </App> )
If you want to stop update <MainContent />
when modal is opened, wrap with <EnabledUpdateIf />
with passing the state of modal visibility to condition
prop.
License
MIT
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK