React Refresh Does not work. #76
-
Hello everyone! I have a custom provider that provides all data provided by Vite from server-side vars using define in vite config.. Now whenever the page is refresh all the variables are undefined. What could be the issue? const [AppContextProvider, useAppContext] = constate(() => {
const { logo, title, navLinks, sidebar, footer } = useMemo(() => {
return __CODOC_APP_CONTEXT__;
}, []);
const routes = useMemo(() => {
return asyncRoutes.find(item => item.path === '/')?.children ?? [];
}, []);
return {
logo,
title,
routes,
sidebar,
navLinks,
footer
} as AppContext;
}); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I am not sure if I understood the question correctly, but if you mean that when you refresh the page (which means the page loads again from the server) it is normal behavior that the context starts being empty again, I would suggest you use local-storage or anything of that sort if you want the data to stay or have default values, use it with useEffect, like the followings:
It's also a good idea to check that the CODOC_APP_CONTEXT is defined and only set it on client side.
|
Beta Was this translation helpful? Give feedback.
I am not sure if I understood the question correctly, but if you mean that when you refresh the page (which means the page loads again from the server) it is normal behavior that the context starts being empty again, I would suggest you use local-storage or anything of that sort if you want the data to stay or have default values, use it with useEffect, like the followings:
It's…