/
sbars
/
claude-code
Обзор
Документация
Войти
/
sbars
/
claude-code
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
hooks/useUpdateNotification.ts
34 строки
982 B
kuberwastaken
init
31 мар 2026, 13:55
31 мар 2026, 13:55
ec53fcb
Код
Авторство
О чём код?
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 }