New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More

@teneff/use-title-effect

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@teneff/use-title-effect

> React hook for changing document.title > > [![NPM version][npm-img-latest]][npm-url] > [![Build Status][build-img]][build-url] > [![Coverage Status][coverage-image]][coverage-url] > [![GitHub issues][issues-image]][issues-url] > [![GitHub stars][github

1.0.1
latest
Version published
Maintainers
1
Created

@teneff/use-title-effect

React hook for changing document.title

NPM version Build Status Coverage Status GitHub issues GitHub stars

Installation

yarn add @teneff/use-title-effect

Preview

Preview

Usage

import useTitleEffect from '@teneff/use-title-effect'

function App() {

  useTitleEffect('React App Title', {
    messages: ['message 1', 'message 2']
  });

  return (
    <div className="App">
     React App Here
    </div>
  );
}

ℹ️ Consider using the hook in the outer components like App

Version 1.0.0 does not revert the original title of the page once the component is unmounted

Options

options.title: string (default: "")

Title is used to provide a permanent page title and it's also provided to the formatter to be enchanced

options.formatter: Formatter<T> (default: see formatter/message)

Formatter is functino accepting object with title and messages and returning array of strings, which are rotated in the given duration

options.duration: number (default: 800)

Time in milliseconds to switch between the different messages resulted from the formatter

Usage with custom message format

  import formatters, { Formatter } from './formatter';

  const messages = [
    {
      message: 'Hello!',
      author: {
        name: 'John Doe'
      }
    },
    {
      message: 'Hey!',
      author: {
        name: 'Jane Doe'
      }
    },
    {
      message: 'U there?',
      author: {
        name: 'John Doe'
      }
    },
  ]

  useTitleEffect(
    "My awesome app",
    {
      messages,
      // reusing the default formatter
      formatter: ({ title, messages }) => formatters.message({
      title,
      messages: messages.map(message => message.author.name)
    })
  })

  useTitleEffect(
    "My awesome app",
    {
      messages,
      // custom formatter
      formatter: ({ title, messages }) => {
        const uniqueAuthors = new Set(messages.map(message => message.author.name))
        return messages.length ? [
          `(${messages.length}) ${title}`,
          `(${messages.length}) You've got messages from ${Array.from(uniqueAuthors).length} contacts`
        ] : [title]
      }
    });

FAQs

Package last updated on 20 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts