import * as React from "react";
import { useSuffixContext } from "../contexts";

export const useGetKey = (props: { "data-id"?: string }) => {
  const id = props?.["data-id"] ?? "";
  return useGetKeyById(id);
};

export const useGetKeyById = (id: string = "") => {
  const suffix = useSuffixContext();
  return React.useMemo(
    () => (id ? (suffix ? `${id}-${suffix}` : id) : ""),
    [suffix, id],
  );
};
