useTitle

Tags:

一个 React Hook,用于管理文档的标题。

演示

源码

用法

请查看 API。

源码

点击下方链接跳转 GitHub 查看源代码。

API

const restore = useTitle(newTitle, options)

新标题 NewTitle

一个 string 类型,代表文档的新标题。

选项 Options

/**
 * 如果模板是一个 `string`,`%s` 将被替换为标题
 */
export type UseTitleOptionsTemplate = string | ((title: string) => string)

export type UseTitleOptions = {
  /**
   * 卸载时恢复原始标题
   *
   * @defaultValue false
   */
  restoreOnUnmount?: boolean
  /**
   * 用于格式化标题的模板
   *
   * @defaultValue '%s'
   */
  template?: UseTitleOptionsTemplate
}

返回值

一个函数,用于恢复到原始标题。