🔥 看看我們的新專案 t0ggles - 您終極的專案管理工具! 🔥

useTheme

Konsta UI 提供了方便的 useTheme Hook,用於偵測由 App 組件KonstaProvider 設定的目前啟用主題(iosmaterial)。

/* App.jsx */
import { App } from 'konsta/react';
import { HomePage } from './path/to/HomePage.jsx';

export default function MyApp() {
  return (
    <>
      {/* set theme on App component */}
      <App theme="ios">
        <HomePage />
      </App>
    </>
  );
}
/* HomePage.jsx */
import { useTheme, Page } from 'konsta/react';

export default function MyApp() {
  // get currently set theme
  const theme = useTheme();

  console.log(theme); // -> 'ios'

  return (
    <>
      <Page>
        {theme === 'ios' ? <p>Theme is iOS</p> : <p>Theme is Material</p>}
      </Page>
    </>
  );
}
程式碼授權條款為 MIT.
2022 © Konsta UI 由 nolimits4web.