Socket
Book a DemoInstallSign in
Socket

@jvllmr/react-component-titles

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jvllmr/react-component-titles

Component-bound titles for React

1.0.5
latest
Source
npmnpm
Version published
Weekly downloads
24
700%
Maintainers
1
Weekly downloads
 
Created
Source

Component-titles

Routine Checks Codecov npm Bundlesize React Bundlesize Solid

A hook for handling browser Document titles bound to components. Previous titles are restored when a component unmounts.

Functionality

The hook adheres to the following rules:

  • It reverts the title when the component unmounts, but only when document.title has the value used by the component
  • The hook listens to the changes of its given value (internally this counts as a new mounted title)
  • When the title changes to an empty string, the hook reverts the title
  • When multiple components with the same title get mounted in a row, the title only gets removed when all components have unmounted
  • When three components get mounted with a title and the second in order unmounts, the title of the first component is saved in the third and loaded when the third component unmounts. Of course this mechanism works with any count of titled components.
  • No state changes and unnecessary re-renders; components notify each other and share state via events and mutable refs

Installation

  • npm i @jvllmr/react-component-titles or yarn add @jvllmr/react-component-titles for React
  • npm i @jvllmr/solid-component-titles or yarn add @jvllmr/solid-component-titles for Solid

Demo

You can find a React demo here

React Code example

// with solid-js use import { createComponentTitle } from "@jvllmr/solid-component-titles"
import { useComponentTitle } from "@jvllmr/react-component-titles";

function MyLoadingComponent() {
	// In solid-js () => string has to be passed
	useComponentTitle("Loading...");

	return <Loader />;
}

API Reference

useComponentTitle (React)

useComponentTitle hook API

function useComponentTitle(title: string): void;

createComponentTitle (Solid)

createComponentTitle hook API

function createComponentTitle(title: Accessor<string>): void;

DocumentTitle

DocumentTitle component API

function DocumentTitle(props: { title: string }): null;

Keywords

document

FAQs

Package last updated on 10 Dec 2023

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

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.