useToggleState

    API

    import useToggleState from '@restart/hooks/useToggleState'
    • useToggleState(initialState: boolean) => [boolean,(value?: undefined | false | true) => void]

      Create a state setter pair for a boolean value that can be "switched". Unlike useState(false), useToggleState will automatically flip the state value when its setter is called with no argument.

      Parameters

      • initialStateboolean

        The initial boolean value

      Return Value [boolean,(value?: undefined | false | true) => void]

      A tuple of the current state and a setter

      const [show, toggleShow] = useToggleState(false)
      return (
      <>
      <button onClick={() => toggleShow()}>
      Toggle
      <button>
      {show && <strong>Now you can see me</strong>}
      </>
      )