10000 pavankumar-patruni’s gists · GitHub
[go: up one dir, main page]

Skip to content

Instantly share code, notes, and snippets.

@pavankumar-patruni
pavankumar-patruni / README.md
Created December 5, 2024 18:47
usePaginatedList

usePaginatedLi 10000 st

A React hook to handle the pagination of an array. This hook provides an easy way to paginate, update page size, and manipulate the list dynamically.

Usage

Here’s how you can use the usePaginatedList hook in your React component:

const {
    paginatedList,
 updateList,
@pavankumar-patruni
pavankumar-patruni / README.md
Created December 5, 2024 18:00
usePagination

usePagination

A React hook to handle pagination logic for lists or tables. It supports dynamic page counts, boundaries, and sibling ranges.

Usage

Here’s how you can use the usePagination hook in your React component:

 const {
    pagination,
 currentPage,
@pavankumar-patruni
pavankumar-patruni / README.md
Created December 4, 2024 10:55
useDebounce

useDebounce

The useDebounce hook is a custom React Hook that delays the update of a value. It is useful for scenarios where you want to minimize the number of expensive computations or API calls, such as while typing in a search bar.

Usage

Here’s how you can use the useDebounce hook in your React component:

const [search, setSearch, debouncedSearch] = useDebounce("", 300);
@pavankumar-patruni
pavankumar-patruni / README.md
Created December 4, 2024 09:41
useMountedOnce

useMountedOnce

useMountedOnce is a custom React hook that allows you to run a callback function only once when the component is mounted. This hook ensures that the callback is executed only during the component's first render and is not triggered on subsequent re-renders. It’s useful when you need to perform an action (e.g., data fetching, subscriptions) just once after the component has mounted, without triggering it on every render.

Usage

Here’s how you can use the useApiService hook in your React component:

useMountedOnce(() => {
    const socket = new WebSocket('wss://example.com/socket');
 
@pavankumar-patruni
pavankumar-patruni / README.md
Last active December 14, 2024 13:28
useApiService

useApiService

The useApiService hook is a custom React hook designed to handle API calls in a declarative manner while managing the request's lifecycle (loading, success, and failure states).

Usage

Here’s how you can use the useApiService hook in your React component:

const { data, error, loading, trigger } = useApiService<DataType>(
  "https://api.example.com/data", 
 { triggerOnLoad: false, method: "GET" }
@pavankumar-patruni
pavankumar-patruni / README.md
Last active December 4, 2024 07:51
useToggledState

useToggledState

The useToggledState hook is a custom React hook designed to manage boolean states with ease. It simplifies toggling operations, which are common in UI components, such as showing/hiding modals, switching themes, or toggling dropdown menus.

Usage

Here’s how you can use the useToggledState hook in your React component:

const [isToggled, toggle] = useToggledState();
@pavankumar-patruni
pavankumar-patruni / README.md
Last active December 5, 2024 19:34
usePersistedState

usePersistedState

The usePersistedState hook is a custom React hook designed to provide state management with persistence. It combines React's useState with localStorage to ensure the state is saved across page reloads and browser sessions.

Usage

Here’s how you can use the usePersistedState hook in your React component:

const [value, setValue] = usePersistedState("myKey", initialValue);
class Queue {
constructor(...items) {
this.queue = [...items];
}
enqueue(...items) {
this.queue.push(...items);
}
dequeue() {
class Stack {
constructor(...items) {
this.stack = [...items];
}
push(...items) {
this.stack.push(...items);
}
pop() {
class Node {
constructor(value, next) {
this.value = value;
this.next = next;
}
}
class LinkedList {
constructor() {
this.head = null;
0