From 26e6c006413c21ec0ad8a0bb546d0f645560aa2c Mon Sep 17 00:00:00 2001 From: Melloware Date: Thu, 10 Nov 2022 13:22:49 -0500 Subject: [PATCH] Fix #2671: Showcase store theme in local storage (#2772) * Fix #2671: Showcase store theme in local storage * Fix #2671: Showcase store theme in local storage * Update _app.js --- pages/_app.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pages/_app.js b/pages/_app.js index 8de7c60693..4f507a6cce 100644 --- a/pages/_app.js +++ b/pages/_app.js @@ -6,12 +6,13 @@ import '../styles/demo/demo.scss'; import Layout from '../components/layout/layout'; import { useEffect, useRef, useState } from 'react'; import fetchNews from '../service/NewsService'; +import { useStorage } from '../components/lib/hooks/useStorage'; export default function MyApp({ Component }) { const [dark, setDark] = useState(false); - const [theme, setTheme] = useState('lara-light-indigo'); + const [theme, setTheme] = useStorage('lara-light-indigo', 'primereact-showcase-theme'); + const [storedNews, setStoredNews] = useStorage('', 'primereact-news'); const [newsActive, setNewsActive] = useState(false); - const storageKey = 'primereact'; const announcement = useRef(null); useEffect(() => { @@ -48,7 +49,7 @@ export default function MyApp({ Component }) { hiddenNews: announcement.current.id }; - localStorage.setItem(storageKey, JSON.stringify(item)); + setStoredNews(item); }, onThemeChange: (newTheme, dark) => { setDark(dark);