use-gorkem v2.2.2
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
- Website: gorkemsinirlioglu.com
- Github: @GorkemSinirlioglu
- LinkedIn: @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.