Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Is this indented feature?: Context data is maintained regardless of component lifeCycle if the overlay has the same ID. #87

Closed
nayounsang opened this issue Sep 27, 2024 · 1 comment

Comments

@nayounsang
Copy link

hello.
I used a context provider inside the overlay.
Give value to Provider with props.

  const handleFileButtonClick = () => {
    overlay.open(
      ({ isOpen, close }) => (
        <ModalContainer isOpen={isOpen} onClose={close}>
          <FileUploadAndSelectModal providerValue={providerValue} />
        </ModalContainer>
      ),
      { overlayId: `File-Upload-Select` }
    );
  };
// FileUploadAndSelectModal
const FileUploadAndSelectModal = ({providerValue})=>{
return(
<MyContext.Provider value={providerValue}>
{/*....*/}
</MyContext.Provider?
)
}

This modal can be opened with sameID:File-Upload-Select on multiple pages.
Different pages inject different providerValue.
I had to refresh the page to get the desired providerValue within the modal.
I solved this by giving each overlay a different id, such as uuid.
Is this indented feature?

@ojj1123
Copy link
Contributor

ojj1123 commented Sep 29, 2024

Yeah this is intended. Given the same overlayId, if you don't call unmount callback, the same overlay is in memory.
related issue: #57

So if you want to reset providerValue, call unmount callback after close or just call unmount for closing the overlay.

  const handleFileButtonClick = () => {
    overlay.open(
      // `unmount` instead of `close`
      ({ isOpen, unmount }) => (
        <ModalContainer isOpen={isOpen} onClose={unmount}>
          <FileUploadAndSelectModal providerValue={providerValue} />
        </ModalContainer>
      ),
      { overlayId: `File-Upload-Select` }
    );
  };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants