useToggle

PHOTO EMBED

Sun Feb 26 2023 04:30:38 GMT+0000 (Coordinated Universal Time)

Saved by @highiq #react #hooks

import { useState } from "react"

export default function useToggle(defaultValue) {
  const [value, setValue] = useState(defaultValue)

  function toggleValue(value) {
    setValue(currentValue =>
      typeof value === "boolean" ? value : !currentValue
    )
  }

  return [value, toggleValue]
}
content_copyCOPY

Add this to my React Hooks library

https://dev.to/arafat4693/15-useful-react-custom-hooks-that-you-can-use-in-any-project-2ll8