question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to close react-burger-menu when link click in a component?

See original GitHub issue

i want to close my sidebar menu when a link is click not outside or cross button click just link click then my sidebar menu automatically close itself. But problem is my link is under another component , Suppose my component <ShipForMe/> and my link is under <ShipForMe/> like <NavLink to="/dashboard/ship-for-me/my-request/pending">My Request</NavLink>

Sidebar.js

<div className="sidebar-wrap " id="outer-container">
                <div className="dashboard-menu rounded">
                    <ShipForMe/>
                    <MyWallet/>
                    <Profiles/>
                    <div className="sidebar-item ds-item">
                        <div className="sidebar-item__title">
                            <NavLink to="">VIP Center</NavLink>
                        </div>
                    </div>
                </div>
                <div className="dashboard-responsive rounded">
                    <Menu pageWrapId={ "page-wrap" } outerContainerId={ "outer-container" } isOpen={false}>
                            <div id="page-wrap" style={{marginTop: '-25%'}}>
                                <ShipForMe handleUrl={handleUrl}/>
                                <MyWallet/>
                                <Profiles/>
                                <div className="sidebar-item ds-item">
                                    <div className="sidebar-item__title">
                                        <NavLink to="">VIP Center</NavLink>
                                    </div>
                                </div>
                            </div>
                    </Menu>
                </div>
            </div>

ShipForMe.js

<div className="ship-wrap ds-item">
         <div className="sidebar-item">
            <div className="sidebar-item__title">
               Ship for me
            </div>
            <ul className="sidebar-item__lists">
               <li>
                  <NavLink to="/dashboard/ship-for-me/my-request/pending">My Request</NavLink>
               </li>
               <li>
                  <NavLink to="/dashboard/ship-for-me/forwarding-parcel/abroad-to-bd">My Forwarding Parcel</NavLink>
               </li>
            </ul>
         </div>
      </div>

Note: isOpen{flase} is not working, it is only working when link is physical there.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
negomicommented, Oct 20, 2020

Yes, they both demonstrate the same concepts, so you can use whichever you like.

0reactions
Koushik-Sahacommented, Oct 20, 2020

can i use 2nd example (react hooks) for my problem

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to close react-burger-menu when link click in a ...
In your Menu component, add: (1) onOpen={handleOpen} , (2) onClose={handleOpen} , and (3) isOpen={isOpen} properties.
Read more >
Closing a navigation menu in React - DEV Community ‍ ‍
This is surprisingly easy. I have a mobile nav, which has a hamburger icon to open it. Once it's open that icon changes...
Read more >
react-burger-menu examples - CodeSandbox
Learn how to use react-burger-menu by viewing and forking react-burger-menu example apps on CodeSandbox.
Read more >
React Menu component - Material UI - MUI
When close to a screen edge, a basic menu vertically realigns to make sure that all menu items are completely visible. Choosing an...
Read more >
How to create a multilevel dropdown menu in React
Closing the dropdown menu when users click outside it ... we will replace it with the Link or NavLink component from the react-router-dom...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found