跳到主要内容

访问主题

如果你需要在使用 Restyle 创建的组件之外手动访问主题,请使用 useTheme 钩子

const Component = () => {
const theme = useTheme<Theme>();
const {cardPrimaryBackground} = theme.colors;
// ...
};

通过这样做而不是直接导入主题对象,可以很容易地在运行时切换主题,例如在你的应用中实现暗黑模式切换