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

How to avoid child menu render when it is not visible? #1081

Closed
seperman opened this issue Sep 14, 2023 · 2 comments
Closed

How to avoid child menu render when it is not visible? #1081

seperman opened this issue Sep 14, 2023 · 2 comments
Labels
question Ask for help and support

Comments

@seperman
Copy link

Hello,
Thanks for the great menu library.

I have some menu components that depend on the state in the rest of the page.
For example, the contents of editMenu will change based on the user interactions in another component in the page. However most of the times, the editMenu is hidden until the user clicks on the MenuButton. How can I avoid the unnecessary editMenu re-renders while it is not visible? It only needs to be rendered when the user clicks on MenuButton.

    <Menu transition menuButton={<MenuButton>Edit</MenuButton>}>
      {editMenu}
    <Menu/>
"react": "^17.0.2",
"react-dom": "^17.0.2",
"@szhsin/react-menu": "^4.0.3",
@seperman seperman added the question Ask for help and support label Sep 14, 2023
@szhsin
Copy link
Owner

szhsin commented Sep 14, 2023

Hi @seperman , this is a great question. In fact, we can avoid re-rendering menu items by unmounting them, which can be achieved by the unmountOnClose prop of Menu component.

Here is a sandbox example.

Notice that when typing into the input while menu is closed, the menu items are not rendered.

@seperman
Copy link
Author

Thanks for the prompt response!

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

No branches or pull requests

2 participants