Skip to content

A modern and easy to use dashboard. 80+ integrations. 20K+ icons built in. Authentication out of the box. No YAML, drag and drop configuration.

611 B
Raw Blame
"use client";

import { useMemo } from "react";

import { formatByteRate, formatBytes, formatBytesPair } from "@homarr/common";

import { useSettings } from "./context";

export const useByteFormatter = () => {
  const { byteUnitSystem } = useSettings();

  return useMemo(
    () => ({
      formatBytes: (bytes: number) => formatBytes(bytes, { unit: byteUnitSystem }),
      formatBytesPair: (used: number, total: number) => formatBytesPair(used, total, { unit: byteUnitSystem }),
      formatByteRate: (bytes: number) => formatByteRate(bytes, { unit: byteUnitSystem }),
    }),
    [byteUnitSystem],
  );
};