negomi / react-burger-menu

:hamburger: An off-canvas sidebar component with a collection of effects and styles using CSS transitions and SVG path animations
http://negomi.github.io/react-burger-menu/
MIT License
5.05k stars 586 forks source link

Unclear how to attach function to the burger menu button #378

Closed Epyon616 closed 4 years ago

Epyon616 commented 4 years ago

After following the documentation on, I have got a menu and the default burger menu button, however it is not clear how I'm supposed to add my toggle function to this button, if I currently click the menu button nothing happens, but if I add another button and give it an onclick method to toggle isOpen it works fine.

Am I missing something?

Thanks in advance

negomi commented 4 years ago

Hey @LeeDownshift, if you're using the default button, it doesn't need a toggle function added manually. It will already open the menu.

If you want to keep track of the menu state externally and use the isOpen prop, you should instead listen for the state change event (using onStateChange).

Here's an example of how that might look (just without the CustomIcon): https://github.com/negomi/react-burger-menu/wiki/FAQ#i-want-to-control-the-open-state-programmatically-but-i-dont-understand-how-to-use-the-isopen-prop