You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
exportdefaultfunctionApp(){console.log("App render");constshowModalA=()=>{NiceModal.show(ModalConstant.modalA,{});};return(<divclassName="App"><h1>Muti Modal Re-render demo</h1><Buttonvariant="secondary"onClick={showModalA}>
Show Modal [A]
</Button></div>);}
muti modal.tsx
Only the title is different
In ModalA.tsx, click will show ModalB
In ModalB.tsx, click will show ModalC ...
importBootstrapModalfrom"react-bootstrap/Modal";importNiceModal,{useModal,bootstrapDialog}from"@ebay/nice-modal-react";import{ModalConstant}from"../constant";importButtonfrom"react-bootstrap/Button";constModalA=NiceModal.create(()=>{constmodal=useModal();console.log("Modal [A] render",`id: ${modal.id}, visible: ${modal.visible}`);constshowModalB=()=>{NiceModal.show(ModalConstant.modalB,{});};return(<BootstrapModal{...bootstrapDialog(modal)}><BootstrapModal.HeadercloseButton><BootstrapModal.Title>Modal A</BootstrapModal.Title></BootstrapModal.Header><BootstrapModal.Body><p>This is modal A.</p><Buttonvariant="secondary"onClick={showModalB}>
Show Modal [B]
</Button></BootstrapModal.Body><BootstrapModal.Footer><Buttonvariant="secondary"onClick={modal.hide}>
Close
</Button><Buttonvariant="primary"onClick={modal.hide}>
Save changes
</Button></BootstrapModal.Footer></BootstrapModal>);});exportdefaultModalA;
Step
Call showModalA() in App.tsx, it opens the Modal, without re-rendering the App(desired);
Call showModalB() in ModalA.tsx, it opens the Modal B, causes a re-render to the Modal A(not desired).
Call showModalC() in ModalB.tsx, it opens the Modal C, causes a re-render to the Modal A and Modal B(not desired).
Business description
In my App, there are a lot of modals that need to be displayed, so in some business scenarios, there may be 5 or more modals displayed cascading.
As follows:
Modal-A
-- Modal-B
------ Modal-C
---------- Modal-D
Code description
Example link
index.tsx
, call register functionApp.tsx
modal.tsx
ModalA.tsx
, click will showModalB
ModalB.tsx
, click will showModalC
...Step
showModalA()
inApp.tsx
, it opens the Modal, without re-rendering the App(desired);showModalB()
inModalA.tsx
, it opens the Modal B, causes a re-render to the Modal A(not desired).showModalC()
inModalB.tsx
, it opens the Modal C, causes a re-render to the Modal A and Modal B(not desired).Questions
As you can see, opening the next Modal causes the previous modals re-render.
How can I get around this?
The text was updated successfully, but these errors were encountered: