Get 2024 Templates Mega Bundle!14 Bootstrap, Vue & React Templates + 3 Vector Sets
Get for 99$

LayoutSplashScreen doesn't work, metronic 7 react


i need proper example of splash screen logic


export default function App({ store, persistor, basename }) {
return (
/* Provide Redux store */
<Provider store={store}>
{/* Asynchronously persist redux stores and show `SplashScreen` while it"s loading. */}
<PersistGate persistor={persistor} loading={<LayoutSplashScreen />}>
{/* Add high level `Suspense` in case if was not handled inside the React tree. */}
<React.Suspense fallback={<LayoutSplashScreen />}>
{/* Override `basename` (e.g: `homepage` in `package.json`) */}
<BrowserRouter basename={basename}>
{/*This library only returns the location that has been active before the recent location change in the current window lifetime.*/}
<MaterialThemeProvider>
{/* Provide `react-intl` context synchronized with Redux state. */}
<I18nProvider>
{/* Render routes with provided `Layout`. */}
<Routes />
</I18nProvider>
</MaterialThemeProvider>
</BrowserRouter>
</React.Suspense>
</PersistGate>
</Provider>
);
}



import React, {createContext, useContext, useState, useEffect} from "react";

const MetronicSplashScreenContext = createContext();

export function MetronicSplashScreenProvider({ children }) {
const [count, setCount] = useState(0);
let visible = count > 0;

useEffect(() => {
const splashScreen = document.getElementById("splash-screen");

// Show SplashScreen
if (splashScreen && visible) {
splashScreen.classList.remove("hidden");

return () => {
splashScreen.classList.add("hidden");
};
}

// Hide SplashScreen
let timeout;
if (splashScreen && !visible) {
timeout = setTimeout(() => {
splashScreen.classList.add("hidden");
}, 3000);
}

return () => {
clearTimeout(timeout);
};
}, [visible]);

return (
<MetronicSplashScreenContext.Provider value={setCount}>
{children}
</MetronicSplashScreenContext.Provider>
);
}

export function LayoutSplashScreen({ visible = true }) {
// Everything are ready - remove splashscreen
const setCount = useContext(MetronicSplashScreenContext);

useEffect(() => {
if (!visible) {
return;
}

setCount(prev => {
return prev + 1;
});

return () => {
setCount(prev => {
return prev - 1;
});
};
}, [setCount, visible]);

return null;
}


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (2)


Hi Alexander,

I will check your case tonight and will come back with a response then (cause it's Metronic 7, the current version is 8.0.36 and it takes some time to run+test the case).

Regards,
Keenthemes support



I've just checked the code, and it works, as expected. In case we comment on it, I see a splash screen from 'public/index.html' file. But we are using it only for the first application load. If you need something for your Suspent fallback= you have to implement your own SplashScreen component.

Regards,
Keenthemes support


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(