问题描述
我是新来的反应者。我想基于props
的值导入“ darkMode.css”或“ lightmode.css”(到基于类的组件)。
想象一下我具有以下功能(在基于类的组件中):
cssName = () => (this.props.mode === "dark"? "darkMode.css":"lightmode.css")
是否可以使用此功能导入“ darkMode.css”或“ lightmode.css”?
感谢您的帮助!
解决方法
cssName = () => {
if (this.props.mode === 'dark') {
return import('darkmode.css').then((module) =>
// whatever you want to do with module
);
}
return import('lightMode.css').then((module) =>
// whatever you want to do with module
);
};