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

Causes UI to stop responding to state changes #725

Open
KTPenrose opened this issue Jul 17, 2023 · 1 comment
Open

Causes UI to stop responding to state changes #725

KTPenrose opened this issue Jul 17, 2023 · 1 comment

Comments

@KTPenrose
Copy link

I have a MaterialTable that is bound to a state variable that contains an array. It works beautifully, until I make the container dialog draggable.

... const [attachments, setAttachments] = useState([]); ... const onOkAttachmentHandler = (file) => { //add attachment if (file !== null) { let attachment = { ownerId: props.entityId, labId: props.labId, filename: file.name, file: file, archive: false }; setAttachments((previousAttachments) => { let newList = [...previousAttachments, attachment]; return newList; }); props.attachmentAdded(attachment); } setAddAttachmentDialogVisible(false); } ... <MaterialTable title="Attachments" data={attachments} ...

@JEKO10
Copy link

JEKO10 commented Jul 7, 2024

The issue you're facing is likely due to the MaterialTable losing its event listeners or being rendered incorrectly when the container dialog becomes draggable.

The first solution that comes to my mind is that you can re-render MaterialTable on Dialog Open/Close:

  1. Add a state variable to track the visibility of the draggable dialog.
  2. Update that state to also trigger a re-render of the MaterialTable component.

The second solution is to use a Portal for the MaterialTable

  1. Import and wrap the MaterialTable component with the Portal component.

Be careful with the first solution because you don't want to cause unnecessary re-renders if the dialog content changes frequently.

Let me know if you have more question :)

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