Getting started

Getting Started

A quick tutorial to get you up and running with Easy Hooks TS.

Implementing useToggle

In this quick tutorial, we will install custom hook useToggle.

1. Install the hook

Install the custom hook from your command line.

pNPM: Fast, disk space efficient package manager.

bash
  pnpm install easy-hooks-ts

2. Import the custom hook

Import and structure the parts.

demo.js
import { useToggle } from 'easy-hooks-ts'
 
export const Component = () => {
  const [value, toggle, setValue] = useToggle()
 
  const customToggle = () => setValue((x: boolean) => !x)
 
  return (
    <>
      <p>
        Value is <code>{value.toString()}</code>
      </p>
      <button onClick={() => setValue(true)}>set true</button>
      <button onClick={() => setValue(false)}>set false</button>
      <button onClick={toggle}>toggle</button>
      <button onClick={customToggle}>custom toggle</button>
    </>
  )
}

Demo