I have this tree of components:
Father
Son
Childrens
Daughter
Childrens2
Modal
Everytime that Modal is open (by setting this.setState({ openSimpleModal: true });) or it's close (setting state as false) the componentes Son, Daughter, and their childrens components are re-rendered to. Is there a way where I can open and close the Modal, but not allowing to re-render 1 specific component, for example, Son (and their childrens) but re-rendering the rest? (Daughter, etc) but ONLY when the Modal opens or close. I need to render each child component in other scenarios, but I need to stop re-rendering when the Modal opens/close
What I tried is using
shouldComponentUpdate(nextProps: Readonly<P>, nextState: Readonly<S>, nextContext: any): boolean {
return this.state.openSimpleModal === nextState.openSimpleModal
}
and deciding if the state of the modal changed and in that case returns false, but it's not working, because of course the modal wont shows.
openSimpleModalisfalse, for example, there's no way to not re-render since it has to recreate the elements. - Jacob