2.2.2 • Published 2 years ago

use-gorkem v2.2.2

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

Provides you with hooks to speed up your development process

useArray

Manage your state arrays properly

import { useArray } from "use-gorkem"

export const MyComponent = () => {
  const { array, filter, update, clear, set, push, remove } = useArray([
    10, 13, 100, 200
  ])

  // array: this is the current state of your array
  // filter((): function): example: filter(a => a !== 13)
  // update(n: int,s: any): example: update(2, "Hello World")
  // clear(): sets array to []
  // set(n: any[]): set([1,2,3]) would set array to [1,2,3]
  // push(n: int): adds item to the end of your array
  // remove(n: int): removes item at index n

  return <></>
}

You can also have your own names for specific items (as you wish):

  const { array: myArray, filter: myFilter, update: myUpdate, clear, set, push, remove } = useArray([
    10, 13, 100, 200
  ])

useToggle

Instead of using useState for a toggle, use useToggle

  import { useToggle } from "use-gorkem"


export const MyComponent = () => {
  const [myValue, toggle] = useToggle(false)
  return (
    <div>
      <div>{myValue ? "true" : "false"}</div>
      <button onClick={toggle}>Toggle</button>
    </div>
  )
}

useDebounce

In the following example, if "Increment Counter" button was not pressed for minimum 2 seconds, it will do: alert(counter). Use case: API calls after user action

import { useState } from "react"
import { useDebounce } from "use-gorkem"

export const MyComponent = () => {
  const [counter, setCounter] = useState(5)
  useDebounce(() => alert(counter), 2000, [counter])

  return (
    <div>
      <div>{counter}</div>
      <button onClick={() => setCounter(cur => cur + 1)}>Increment Counter</button>
    </div>
  )

}

Sponsor

⚽ Booklified Football Manager is a browser based strategy game where you can become a football manager. Coach your favourite football club! https://fm-land.booklified.com

📅 Booklified is a scheduling app. It lets other people easily book on your calendar. https://booklified.com

▶️ Youtube: ▶https://www.youtube.com/channel/UCa5K76Kap1iUqqML9JLhmxw

Author

👤 GorkemSinirlioglu

🤝 Contributing

Contact me if you would like to access the source code, or if you are facing any issues.

Buy me Coffee ☕

If this project helped you

📝 License

This project is MIT licensed.


2.2.2

2 years ago

2.2.1

2 years ago

2.1.10

2 years ago

2.1.9

2 years ago

2.1.8

2 years ago

2.1.7

2 years ago

2.0.7

2 years ago

2.0.6

2 years ago

2.0.5

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago