Function useCounter

  • A custom hook to manage a counter.

    Parameters

    • options: {
          initialCount: number;
          step: number;
      } = DEFAULT_OPTIONS

      An object to define custom behaviour of the counter.

      • initialCount: number

        The initial value of the counter.

      • step: number

        The increment to add or sub for every operation.

    Returns {
        count: number;
        decrement: (() => void);
        increment: (() => void);
    }

    An object containing the current value of the counter and some functions to update it.

    • count: number
    • decrement: (() => void)
        • (): void
        • Decrement the counter using the step argument.

          Returns void

    • increment: (() => void)
        • (): void
        • Increment the counter using the step argument.

          Returns void

    Example

    // Initialize a counter with a step size of 2
    const { count, increment, decrement } = useCounter({ initialCount: 0, step: 2 });
    // Increment the counter
    increment(); // count becomes 2
    // Decrement the counter
    decrement(); // count becomes 0

Generated using TypeDoc