📄 File detail

hooks/useUpdateNotification.ts

🧩 .ts📏 35 lines💾 982 bytes📝 text
← Back to All Files

🎯 Use case

This file lives under “hooks/”, which covers reusable UI or integration hooks. On the API surface it exposes getSemverPart, shouldShowUpdateNotification, and useUpdateNotification — mainly functions, hooks, or classes. Dependencies touch React UI and version comparison.

Generated from folder role, exports, dependency roots, and inline comments — not hand-reviewed for every path.

🧠 Inline summary

import { useState } from 'react' import { major, minor, patch } from 'semver' export function getSemverPart(version: string): string { return `${major(version, { loose: true })}.${minor(version, { loose: true })}.${patch(version, { loose: true })}`

📤 Exports (heuristic)

  • getSemverPart
  • shouldShowUpdateNotification
  • useUpdateNotification

📚 External import roots

Package roots from from "…" (relative paths omitted).

  • react
  • semver

🖥️ Source preview

import { useState } from 'react'
import { major, minor, patch } from 'semver'

export function getSemverPart(version: string): string {
  return `${major(version, { loose: true })}.${minor(version, { loose: true })}.${patch(version, { loose: true })}`
}

export function shouldShowUpdateNotification(
  updatedVersion: string,
  lastNotifiedSemver: string | null,
): boolean {
  const updatedSemver = getSemverPart(updatedVersion)
  return updatedSemver !== lastNotifiedSemver
}

export function useUpdateNotification(
  updatedVersion: string | null | undefined,
  initialVersion: string = MACRO.VERSION,
): string | null {
  const [lastNotifiedSemver, setLastNotifiedSemver] = useState<string | null>(
    () => getSemverPart(initialVersion),
  )

  if (!updatedVersion) {
    return null
  }

  const updatedSemver = getSemverPart(updatedVersion)
  if (updatedSemver !== lastNotifiedSemver) {
    setLastNotifiedSemver(updatedSemver)
    return updatedSemver
  }
  return null
}