Magic Modallatest
Guides

Replace open content

Use update() when an external controller must replace an open modal component.

Keep state inside the modal for normal UI changes. React can re-render that component without changing the stack entry.

update() is an advanced API for a value controlled outside the modal. The function comes from the handle returned by show():

const { modalID, update } = magicModal.show(() => <UploadModal progress={0} />);

await uploadFile(file, {
  onProgress(progress) {
    update(() => <UploadModal progress={progress} />);
  },
});

magicModal.hide(undefined, { modalID });

The stack entry keeps the same position, backdrop, configuration, ID, and pending promise. React receives a new component type for its content.

The new component mounts from scratch

Local state, refs, and effects from the previous component are discarded. Keep modal-owned state in the component, context, or a store. Reserve update() for external orchestration that accepts a full remount.