admin管理员组文章数量:1332107
I have a ponent ProductList - it's a parent ponent. In m render method i wrote such code
return (
<div>
<CustomBreadCrumbs routes={this.props.routes} params={this.props.params} />
{ this.props.children ? this.props.children :
<section className="content">
Parent
</section>
}
</div>
);
When I edit some info in child ponent my parent ponent rerender, but i want prevent it. How i can do it?
I have a ponent ProductList - it's a parent ponent. In m render method i wrote such code
return (
<div>
<CustomBreadCrumbs routes={this.props.routes} params={this.props.params} />
{ this.props.children ? this.props.children :
<section className="content">
Parent
</section>
}
</div>
);
When I edit some info in child ponent my parent ponent rerender, but i want prevent it. How i can do it?
Share Improve this question asked Feb 6, 2017 at 12:52 NickNick 771 gold badge1 silver badge6 bronze badges1 Answer
Reset to default 4This is impossible, because only on rerendering parent ponent calling rerendering of the child.
As you can see there, if you will prevent rerendring of current element with shouldComponentUpdate
, the childs render methods will not hired.
But dont worry React Only Updates What's Necessary. So, if your html of the parent element will not change, the real DOM will update only child`s html.
Show case
There is an example in official documentation, of how to create forms. In a few words, your main problem, is that you dont save your values anywhere, as I see, you use Redux and passing all of the data via props. Try to change your code, to save the data in the own state of the ponent.
And if you will catch an error on BadRequest, you will fire the code, check the equality, for example for message (of an error) and update your ponent, but your current state, with all user`s data will not be changed.
shouldComponentUpdate(nextProps, nextState) {
//there you will get the new values and check it, if they not equal
}
ponentDidUpdate(prevProps, prevState) {
//there you can do anything with your new values
}
And if you r using Redux, take a look to Redux Form.
本文标签: javascriptHow prevent rerender of parent component in ReactjsStack Overflow
版权声明:本文标题:javascript - How prevent rerender of parent component in React.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742272687a2444603.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论