-1

我是新来的反应。我想根据 的值导入“darkMode.css”或“lightMode.css”(到基于类的组件)props

想象一下我有以下功能(在基于类的组件中):

cssName = () => (this.props.mode === "dark"? "darkMode.css":"lightMode.css")

有没有办法使用这个函数导入“darkMode.css”或“lightMode.css”?

感谢您的帮助!

4

1 回答 1

0
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
  );
};
于 2020-09-30T07:58:41.443 回答