saleor-apps-redis_apl/apps/invoices/src/lib/theme-synchronizer.tsx

26 lines
603 B
TypeScript
Raw Normal View History

2023-02-07 19:25:36 +00:00
import { useAppBridge } from "@saleor/app-sdk/app-bridge";
import { useTheme } from "@saleor/macaw-ui/next";
2023-02-07 19:25:36 +00:00
import { memo, useEffect } from "react";
// todo move to shared
export function ThemeSynchronizer() {
2023-02-07 19:25:36 +00:00
const { appBridgeState } = useAppBridge();
const { setTheme } = useTheme();
2023-02-07 19:25:36 +00:00
useEffect(() => {
if (!setTheme || !appBridgeState?.theme) {
return;
}
if (appBridgeState.theme === "light") {
setTheme("defaultLight");
2023-02-07 19:25:36 +00:00
}
if (appBridgeState.theme === "dark") {
setTheme("defaultDark");
}
}, [appBridgeState?.theme, setTheme]);
2023-02-07 19:25:36 +00:00
return null;
}