useHooks is currently down!
useHooks
Hooks

useToggle

Usage

Easy to use, no configuration required.

app/page.tsx
import { useToggle } from "@pyr33x/hooks";
 
export const App = () => {
  const { current, handleToggle } = useToggle(false);
 
  return (
    <div>
      <p>Current value: {current ? "True" : "False"}</p>
      <button onClick={handleToggle}>Toggle value</button>
    </div>
  );
};

Hook

You can copy & paste the hook below and make it ready to use.

useClient.ts
import { useState } from "react";
 
export const useToggle = (initialValue: boolean) => {
  const [current, setCurrent] = useState(initialValue);
 
  const handleToggle = () => setCurrent((prev) => !prev);
 
  return { current, handleToggle };
};

On this page