React компонент прелоадера: стили, контекст для универсального доступа из любой точки приложения, сам tsx компонент
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import React, { createContext, useState } from "react";
|
||||
import Preloader from "../components/preloader/Preloader";
|
||||
|
||||
interface PreloaderProps{
|
||||
setPreloaderVisible: (preloaderVisible: boolean) => void;
|
||||
setPreloaderText: (preloaderText: string) => void;
|
||||
}
|
||||
|
||||
export const PreloaderContext = createContext<PreloaderProps>({
|
||||
setPreloaderVisible: () => {},
|
||||
setPreloaderText: () => {},
|
||||
});
|
||||
|
||||
export function PreloaderProvider({ children }){
|
||||
const [visible, setVisible] = useState<boolean>(true);
|
||||
const [text, setText] = useState<string>('Страница загружается');
|
||||
|
||||
function setPreloaderVisible(preloaderVisible: boolean){
|
||||
setVisible(preloaderVisible);
|
||||
}
|
||||
|
||||
function setPreloaderText(preloaderText: string){
|
||||
setText(preloaderText);
|
||||
}
|
||||
|
||||
let value = {
|
||||
setPreloaderVisible: setPreloaderVisible,
|
||||
setPreloaderText: setPreloaderText
|
||||
}
|
||||
|
||||
return (
|
||||
<PreloaderContext.Provider value={value}>
|
||||
<Preloader
|
||||
visible={visible}
|
||||
text={text}
|
||||
/>
|
||||
{children}
|
||||
</PreloaderContext.Provider>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user