mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
26 lines
619 B
TypeScript
26 lines
619 B
TypeScript
import { createContext, useContext, useEffect, useRef } from 'react';
|
|
|
|
export interface LayoutContextValue {
|
|
title: string;
|
|
setTitle: (title: string) => void;
|
|
}
|
|
|
|
const LayoutContextDefaultValue = {} as LayoutContextValue;
|
|
export const LayoutContext = createContext(LayoutContextDefaultValue);
|
|
|
|
export const useLayoutTitle = (myTitle: string) => {
|
|
const { title, setTitle } = useContext(LayoutContext);
|
|
const previousTitle = useRef(title);
|
|
|
|
useEffect(() => {
|
|
setTitle(myTitle);
|
|
}, [setTitle, myTitle]);
|
|
|
|
useEffect(
|
|
() => () => {
|
|
setTitle(previousTitle.current);
|
|
},
|
|
[setTitle]
|
|
);
|
|
};
|