WORA : Write Once Use Everywhere
No More Copy Paste

WORA : Write Once Use Everywhere

Hello Bhaiyo and Bhano, Ladies and Gentleman, Boys and Girls.

I hope you have heard about this phrase Necessity is the mother of invention. This phrase is applicable to any new invention in almost every industry.

But in Software industry this phrase Laziness is the father of invention overrides the above one.

Not agree with above statement ?

Let me try to prove that with help of one scenario in Lighting Web Component framework (LWC) and at end of this article you would agree with new phrase.

As a LWC learner/developer you might know about Shadow DOM and how the CSS works for each web component.

I hope you have basic understanding about how CSS works within a particular Component. If not, then please refer below link more better understanding.

With help of above document you got the idea that in order to style each component we would need to write separate CSS for each component. However this restriction gives more power to LWC framework in different context (Will explain in another article)

But as a Lazy developer i have one problem with above restriction because now every time i need to write CSS rule in individual component although some components share same elements and i want to apply same style sheet to all those elements.

For example I use h1 html element in few components and I want that my all components header (h1) must have same CSS definition. So as per new feature I don't need to write h1 style in each component instead i would simply define one lightning web component which will have only one CSS file inside it and will have all common styles which i want to apply for different components.

No alt text provided for this image

As you can see I have defined one component which has CSS file inside it. This CSS has style definition for h1 element.

Now i can use this CSS file in any of the component i want with help of below statement.

No alt text provided for this image

You need to apply this statement in respective Component's CSS file where you want to apply the defined styles.

I have defined two Components and each of them has h1 element.

No alt text provided for this image

I hope you can visualize the output of above component and hope you understood how laziness is father of inventions.

Follow me on Twitter/LinkedIn to get more interesting post/articles about Salesforce and Salesforce and Salesforce.



Manish Sharma

SF AI+Data cloud, Industry Clouds, Past Roles: Solutions Head|Sr Solution|Application Architect | Salesforce AI | AWS | Asc Director(Solution Engineering group: Release Mgmt,DevOps) PMP?, PMI-ACP?,CSM?.,SAFe 4 Agilist.

5 年

Nice rendition to simplify Lwc components esp css reuse.?

要查看或添加评论,请登录

Viren Sa的更多文章

  • Sometimes Age and Certification count comes alone !

    Sometimes Age and Certification count comes alone !

    Here are few things which I should ask to myself ? 1. Do I judge maturity level of person with his/her Age ? 2.

    1 条评论
  • Outcome is same but journey experience matters !

    Outcome is same but journey experience matters !

    “Success is a journey, not a destination. The doing is often more important than the outcome.

    1 条评论
  • ApexGuru OR ApexLearner Quiz 2

    ApexGuru OR ApexLearner Quiz 2

    Unpredictability means what it means. I don't know how you define it.

    3 条评论
  • ApexGuru or ApexLearner Quiz 1

    ApexGuru or ApexLearner Quiz 1

    Can you please help us to find out what will be the correct output on console log for below code snippet as for us this…

    7 条评论
  • What will be the output ?

    What will be the output ?

    Assume we have one Trigger defined on Case Object in Salesforce. Trigger code will look like below.

    3 条评论
  • How much difficult to learn Salesforce ( Admin Role)

    How much difficult to learn Salesforce ( Admin Role)

    **NO TECHNICAL BACKGROUND REQUIRES TO LEARN SALESFORCE ADMIN :) Before to understand how much difficult to learn…

    4 条评论
  • ForceFunda has been launched

    ForceFunda has been launched

    Key to unlock excellence in Salesforce for a beginner as a duck takes to water. Introduction video is here.

社区洞察

其他会员也浏览了