Dynamically load a stylesheet with React

前端 未结 5 1660
夕颜
夕颜 2020-11-29 02:16

I\'m building a CMS system for managing marketing landing pages. On the \"Edit Landing Page\" view, I want to be able to load the associated stylesheet for whichever landing

5条回答
  •  孤独总比滥情好
    2020-11-29 02:41

    Instead of creating elements for stylesheet, you can also try importing your css based on some condition. ECMAScript provides a proposal that enables dynamic module imports, that works as follows:

    if (condition) {
      import('your css path here').then((condition) => {});
    }
    

提交回复
热议问题