cyntler / hamburger-react

Animated hamburger menu icons for React.js weighs only 1.5 KB.
https://hamburger-react.netlify.app
MIT License
963 stars 36 forks source link

Check if user provided `toggle` is defined #31

Closed SimplyComplexable closed 3 years ago

SimplyComplexable commented 3 years ago

Currently this is done using a ternary, which is incorrectly using toggleInternal when toggle is set to false. Update to using nullish coallescing to check if toggle is defined rather than falsey.

luukdv commented 3 years ago

Thanks for the PR!

Could you maybe provide an example of a use case for this change?

mnikolaus commented 3 years ago

@luukdv This will fix trying to set toggle to false outside of Hamburger context. Example, user navigates to other page and you need to close the mobile menu and set hamburger to initial state (toggle: false).

luukdv commented 3 years ago

@mnikolaus That's already possible:

const [toggled, toggle] = useState();

<Hamburger toggled={toggled} toggle={toggle} />

// When user navigates to other page
toggle(false);

Can you provide a code example of the use case that's missing? Thanks!

luukdv commented 3 years ago

Closing due to inactivity.