open-amdocs / webrix

Powerful building blocks for React-based web applications
https://webrix.amdocs.com
Apache License 2.0
432 stars 32 forks source link

Add FORCE argument for "toggle" in "useBooleanState" #99

Open yairEO opened 2 years ago

yairEO commented 2 years ago

it's beneficial for a toggling function to have an optional argument that, if set to true or false, will force the toggle to that state.

This is handy in such cases:

const {visible, toggle} = useVisibilityState();

const foo = bar => toggle(bar) // where bar is a Boolean state 

instead of:

const {visible, show, hide} = useVisibilityState();

const foo = bar => {
  if (bar) 
    show()
  else
    hide()
}