SlideShare a Scribd company logo
I'm Andrii Los,
Frontend Engineer at ITV Project
👋
GitHub: RIP21 Twitter: @RIP212
💄CSS-in-JS 💅
Styling for component era web
💩 Problems of CSS
🤖 How they were addressed
💅 CSS-in-JS features
🤖♀️ CSS-in-JS F.A.Q and its problems 💩
🎉 Future of CSS-in-JS
Problems of CSS 💩
💩 Designed for documents not apps
💩 Globally scoped
💩 Hardly reusable
💩 Leaking
💩 Non-programmatic
💩 Non-modular
💩 CSS develops too slow
How they were addressed 🤖
🤖 LESS
🤖 PostCSS
🤖 SASS
🤖 Stylus
🤖 CSS Modules
🤖 All above with Webpack loaders and plugins
What problems were
preserved? 💩
💩 Non-modular out of the box
💩 Still not componentized enough
💩 Require a lot of class names manual work
💩 Still global and can leak
💩 Reusability still not perfect
So what if we would like to
fix them all in one ultimate
solution? 🤖
💄
Glorious
CSS-in-JS!
💅
CSS-in-JS
💅 styled-components
👩🎤 emotion
💄 glamorous
CSS rules definition
💅 Template string literals
💄 Object React inline-styles notation
👩🎤 Supports both
So what the possibilities?
🎉 Media queries
🎉 Keyframes
🎉 Pseudo classes
🎉 Nested selectors
🎉 It's JS, so you have all its power
🎉 Babel and Webpack optimisations for production
🎉 Total isolation if old global CSS approach is not used
🎉 Easy theming support
So what the possibilities?
🎉 Full interoperability with existent CSS
🎉 Inject global styles if you know what you are doing
🎉 Full support for styling 3rd parties components
🎉 Extend API for easily reuse styles
🎉 react-primitives - React Native, React Sketch, etc.
🎉 Endless of other powerful things that you can
come up with
Main features demo 🤖
What's the problems? 💩
💩 Weak editors support?! It's just strings and objects!
🎉 Nope! Webstorm, VS Code, Sublime Text, Atom support is there!
💩 Formatting! I sure it's just highlights the text, but no formatting!
🎉 Nope! Webstorm formats it perfectly. (Not sure about others though)
💩 Meh! Then I won't use!
🎉 Editors doesn't matter. Prettier is formatting CSS in template literals ;)
💩 But we don't use it!
🤖♀️ What's wrong with you?! It's amazing!
💩 I'm not impressed yet..... I need something. It's stupid to have CSS in JS!
🤷♀️ Okay, but what did you were saying about JSX a few years ago 🤖
💩 PERFORMANCE!
Well, you are a little correct 💩
💩 styled-components performance in unrealistic
benchmarks is very weak
🎉 Good news. Emotion and glamorous have bench
performance only 5-10% slower than CSS Modules
🎉 Real world apps performance is good for all
solutions
🎉 There is a hacks to improve it even further if so
needed
So, what you would
recommend?
styled-components 💅
Why?
💅 11000 stars on GitHub, means lots of contributions
💅 Supports React Native and other renderers
💅 Amazing Jest and other test runners support
💅 A lot of tooling is already done for it
💅 Stylelint support (works for emotion as well)
💅 The best documentation
💅 Better performance - matter of time
Future of CSS-in-JS
🤖 ISTF - Interoperable Style Transfer
Format (Even further performance
improvement, CSS-in-JS styles interop)
🤷 Extreme styles optimisations to reduce
amount of CSS code up to 30-60%
(depends on codebase size)
That's all folks! 👋
GitHub: RIP21 Twitter: @RIP212
List of links and resources 🔗
• Sandbox for this speech
• A unified styled language @markdalgleish - MUST READ (pick on
CSS-in-JS by co-author of CSS Modules)
• styled-components documentation
• emotion documentation and full of perf demos of emotion in its
authors twitter
• glamorous documentation
• Amazing article about styled-components future and CSS-in-JS in
overall by one of the authors of s-c
• Template string literals or Object notations, what to choose? Read
that

More Related Content

What's hot

My Top 10 Secret Weapons for Frontend Development
My Top 10 Secret Weapons for Frontend DevelopmentMy Top 10 Secret Weapons for Frontend Development
My Top 10 Secret Weapons for Frontend Development
Geoffrey Plitt
 
귀 Rails의 JS는 안녕하십니까?
귀 Rails의 JS는 안녕하십니까?귀 Rails의 JS는 안녕하십니까?
귀 Rails의 JS는 안녕하십니까?
Cheon Park
 
Anti anti patterns
Anti anti patternsAnti anti patterns
Anti anti patterns
Nick Vanderhoven
 
Gulp.js & webpack
Gulp.js & webpackGulp.js & webpack
Gulp.js & webpack
Ted Hsu
 
React JS for the mobile web
React JS for the mobile webReact JS for the mobile web
React JS for the mobile web
Sreten Madžgalj
 
End-to-End SPA Development using TypeScript
End-to-End SPA Development using TypeScriptEnd-to-End SPA Development using TypeScript
End-to-End SPA Development using TypeScript
Gil Fink
 
Java sutra
Java sutraJava sutra
Java sutra
Nick Vanderhoven
 
Why you should build your own JS Frontend Framework
Why you should build your own JS Frontend FrameworkWhy you should build your own JS Frontend Framework
Why you should build your own JS Frontend Framework
baccigalupi
 
Clojure Lightning Talk
Clojure Lightning TalkClojure Lightning Talk
Clojure Lightning Talk
GiltTech
 
Web Development: Making it the right way
Web Development: Making it the right wayWeb Development: Making it the right way
Web Development: Making it the right way
Yagiz Nizipli
 
Javascript toolkit
Javascript toolkitJavascript toolkit
Javascript toolkit
Marcos Vinícius
 

What's hot (11)

My Top 10 Secret Weapons for Frontend Development
My Top 10 Secret Weapons for Frontend DevelopmentMy Top 10 Secret Weapons for Frontend Development
My Top 10 Secret Weapons for Frontend Development
 
귀 Rails의 JS는 안녕하십니까?
귀 Rails의 JS는 안녕하십니까?귀 Rails의 JS는 안녕하십니까?
귀 Rails의 JS는 안녕하십니까?
 
Anti anti patterns
Anti anti patternsAnti anti patterns
Anti anti patterns
 
Gulp.js & webpack
Gulp.js & webpackGulp.js & webpack
Gulp.js & webpack
 
React JS for the mobile web
React JS for the mobile webReact JS for the mobile web
React JS for the mobile web
 
End-to-End SPA Development using TypeScript
End-to-End SPA Development using TypeScriptEnd-to-End SPA Development using TypeScript
End-to-End SPA Development using TypeScript
 
Java sutra
Java sutraJava sutra
Java sutra
 
Why you should build your own JS Frontend Framework
Why you should build your own JS Frontend FrameworkWhy you should build your own JS Frontend Framework
Why you should build your own JS Frontend Framework
 
Clojure Lightning Talk
Clojure Lightning TalkClojure Lightning Talk
Clojure Lightning Talk
 
Web Development: Making it the right way
Web Development: Making it the right wayWeb Development: Making it the right way
Web Development: Making it the right way
 
Javascript toolkit
Javascript toolkitJavascript toolkit
Javascript toolkit
 

Similar to CSS-in-JS in React: Why, current state, and bright future.

OOScss Architecture For Rails Apps
OOScss Architecture For Rails AppsOOScss Architecture For Rails Apps
OOScss Architecture For Rails Apps
Netguru
 
A journey from sass to css in-js
A journey from sass to css in-jsA journey from sass to css in-js
A journey from sass to css in-js
Martin Jujou
 
Reworking our-workflows
Reworking our-workflowsReworking our-workflows
Reworking our-workflows
nolly00
 
Exploring Our Front-End Workflows
Exploring Our Front-End WorkflowsExploring Our Front-End Workflows
Exploring Our Front-End Workflows
nolly00
 
CSS3 and a brief introduction to Google Maps API v3
CSS3 and a brief introduction to Google Maps API v3 CSS3 and a brief introduction to Google Maps API v3
CSS3 and a brief introduction to Google Maps API v3
Jeffrey Barke
 
Not Just a Pretty Face: How to design and build a cross-CMS CSS framework
Not Just a Pretty Face: How to design and build a cross-CMS CSS frameworkNot Just a Pretty Face: How to design and build a cross-CMS CSS framework
Not Just a Pretty Face: How to design and build a cross-CMS CSS framework
crystalenka
 
Leveling up your JavaScipt - DrupalJam 2017
Leveling up your JavaScipt - DrupalJam 2017Leveling up your JavaScipt - DrupalJam 2017
Leveling up your JavaScipt - DrupalJam 2017
Christian Heilmann
 
Teams, styles and scalable applications
Teams, styles and scalable applicationsTeams, styles and scalable applications
Teams, styles and scalable applications
Vittorio Vittori
 
Enhance Enhance
Enhance EnhanceEnhance Enhance
Enhance Enhance
Andy Parker
 
Untangling spring week4
Untangling spring week4Untangling spring week4
Untangling spring week4
Derek Jacoby
 
The World of Stylesheet Languages
The World of Stylesheet LanguagesThe World of Stylesheet Languages
The World of Stylesheet Languages
Andrea Tino
 
Angular vs React - Devoxx BE 2017
Angular vs React - Devoxx BE 2017Angular vs React - Devoxx BE 2017
Angular vs React - Devoxx BE 2017
Deepu K Sasidharan
 
Is everything we used to do wrong?
Is everything we used to do wrong?Is everything we used to do wrong?
Is everything we used to do wrong?
Russ Weakley
 
CSS Best Practices
CSS Best PracticesCSS Best Practices
CSS Best Practices
nolly00
 
Planning JavaScript and Ajax for larger teams
Planning JavaScript and Ajax for larger teamsPlanning JavaScript and Ajax for larger teams
Planning JavaScript and Ajax for larger teams
Christian Heilmann
 
WordCamp Asheville 2017 - So You Wanna Dev? Join the Team!
WordCamp Asheville 2017 - So You Wanna Dev? Join the Team!WordCamp Asheville 2017 - So You Wanna Dev? Join the Team!
WordCamp Asheville 2017 - So You Wanna Dev? Join the Team!
Evan Mullins
 
Bootstrap for Beginners
Bootstrap for BeginnersBootstrap for Beginners
Bootstrap for Beginners
D'arce Hess
 
Вредные советы .NET разработчикам, Сергей Калинец
Вредные советы .NET разработчикам, Сергей КалинецВредные советы .NET разработчикам, Сергей Калинец
Вредные советы .NET разработчикам, Сергей Калинец
Sigma Software
 
Java 8 - Gateway Drug or End of Line?
Java 8 - Gateway Drug or End of Line?Java 8 - Gateway Drug or End of Line?
Java 8 - Gateway Drug or End of Line?
Garth Gilmour
 
Going native with html5 web components
Going native with html5 web componentsGoing native with html5 web components
Going native with html5 web components
James York
 

Similar to CSS-in-JS in React: Why, current state, and bright future. (20)

OOScss Architecture For Rails Apps
OOScss Architecture For Rails AppsOOScss Architecture For Rails Apps
OOScss Architecture For Rails Apps
 
A journey from sass to css in-js
A journey from sass to css in-jsA journey from sass to css in-js
A journey from sass to css in-js
 
Reworking our-workflows
Reworking our-workflowsReworking our-workflows
Reworking our-workflows
 
Exploring Our Front-End Workflows
Exploring Our Front-End WorkflowsExploring Our Front-End Workflows
Exploring Our Front-End Workflows
 
CSS3 and a brief introduction to Google Maps API v3
CSS3 and a brief introduction to Google Maps API v3 CSS3 and a brief introduction to Google Maps API v3
CSS3 and a brief introduction to Google Maps API v3
 
Not Just a Pretty Face: How to design and build a cross-CMS CSS framework
Not Just a Pretty Face: How to design and build a cross-CMS CSS frameworkNot Just a Pretty Face: How to design and build a cross-CMS CSS framework
Not Just a Pretty Face: How to design and build a cross-CMS CSS framework
 
Leveling up your JavaScipt - DrupalJam 2017
Leveling up your JavaScipt - DrupalJam 2017Leveling up your JavaScipt - DrupalJam 2017
Leveling up your JavaScipt - DrupalJam 2017
 
Teams, styles and scalable applications
Teams, styles and scalable applicationsTeams, styles and scalable applications
Teams, styles and scalable applications
 
Enhance Enhance
Enhance EnhanceEnhance Enhance
Enhance Enhance
 
Untangling spring week4
Untangling spring week4Untangling spring week4
Untangling spring week4
 
The World of Stylesheet Languages
The World of Stylesheet LanguagesThe World of Stylesheet Languages
The World of Stylesheet Languages
 
Angular vs React - Devoxx BE 2017
Angular vs React - Devoxx BE 2017Angular vs React - Devoxx BE 2017
Angular vs React - Devoxx BE 2017
 
Is everything we used to do wrong?
Is everything we used to do wrong?Is everything we used to do wrong?
Is everything we used to do wrong?
 
CSS Best Practices
CSS Best PracticesCSS Best Practices
CSS Best Practices
 
Planning JavaScript and Ajax for larger teams
Planning JavaScript and Ajax for larger teamsPlanning JavaScript and Ajax for larger teams
Planning JavaScript and Ajax for larger teams
 
WordCamp Asheville 2017 - So You Wanna Dev? Join the Team!
WordCamp Asheville 2017 - So You Wanna Dev? Join the Team!WordCamp Asheville 2017 - So You Wanna Dev? Join the Team!
WordCamp Asheville 2017 - So You Wanna Dev? Join the Team!
 
Bootstrap for Beginners
Bootstrap for BeginnersBootstrap for Beginners
Bootstrap for Beginners
 
Вредные советы .NET разработчикам, Сергей Калинец
Вредные советы .NET разработчикам, Сергей КалинецВредные советы .NET разработчикам, Сергей Калинец
Вредные советы .NET разработчикам, Сергей Калинец
 
Java 8 - Gateway Drug or End of Line?
Java 8 - Gateway Drug or End of Line?Java 8 - Gateway Drug or End of Line?
Java 8 - Gateway Drug or End of Line?
 
Going native with html5 web components
Going native with html5 web componentsGoing native with html5 web components
Going native with html5 web components
 

Recently uploaded

Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
camseq
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
JamalHussainArman
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Christina Lin
 
Exception Handling notes in java exception
Exception Handling notes in java exceptionException Handling notes in java exception
Exception Handling notes in java exception
Ratnakar Mikkili
 
Question paper of renewable energy sources
Question paper of renewable energy sourcesQuestion paper of renewable energy sources
Question paper of renewable energy sources
mahammadsalmanmech
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
gerogepatton
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
Aditya Rajan Patra
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
SyedAbiiAzazi1
 
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
ihlasbinance2003
 
A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...
nooriasukmaningtyas
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
MIGUELANGEL966976
 
Wearable antenna for antenna applications
Wearable antenna for antenna applicationsWearable antenna for antenna applications
Wearable antenna for antenna applications
Madhumitha Jayaram
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
KrishnaveniKrishnara1
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
kandramariana6
 
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSA SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
IJNSA Journal
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
NidhalKahouli2
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
gestioneergodomus
 
sieving analysis and results interpretation
sieving analysis and results interpretationsieving analysis and results interpretation
sieving analysis and results interpretation
ssuser36d3051
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
IJECEIAES
 
Low power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniquesLow power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniques
nooriasukmaningtyas
 

Recently uploaded (20)

Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
 
Exception Handling notes in java exception
Exception Handling notes in java exceptionException Handling notes in java exception
Exception Handling notes in java exception
 
Question paper of renewable energy sources
Question paper of renewable energy sourcesQuestion paper of renewable energy sources
Question paper of renewable energy sources
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
 
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
 
A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
 
Wearable antenna for antenna applications
Wearable antenna for antenna applicationsWearable antenna for antenna applications
Wearable antenna for antenna applications
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
 
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSA SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
 
sieving analysis and results interpretation
sieving analysis and results interpretationsieving analysis and results interpretation
sieving analysis and results interpretation
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
 
Low power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniquesLow power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniques
 

CSS-in-JS in React: Why, current state, and bright future.

  • 1. I'm Andrii Los, Frontend Engineer at ITV Project 👋 GitHub: RIP21 Twitter: @RIP212
  • 2. 💄CSS-in-JS 💅 Styling for component era web
  • 3. 💩 Problems of CSS 🤖 How they were addressed 💅 CSS-in-JS features 🤖♀️ CSS-in-JS F.A.Q and its problems 💩 🎉 Future of CSS-in-JS
  • 4. Problems of CSS 💩 💩 Designed for documents not apps 💩 Globally scoped 💩 Hardly reusable 💩 Leaking 💩 Non-programmatic 💩 Non-modular 💩 CSS develops too slow
  • 5. How they were addressed 🤖 🤖 LESS 🤖 PostCSS 🤖 SASS 🤖 Stylus 🤖 CSS Modules 🤖 All above with Webpack loaders and plugins
  • 6. What problems were preserved? 💩 💩 Non-modular out of the box 💩 Still not componentized enough 💩 Require a lot of class names manual work 💩 Still global and can leak 💩 Reusability still not perfect
  • 7. So what if we would like to fix them all in one ultimate solution? 🤖
  • 10. CSS rules definition 💅 Template string literals 💄 Object React inline-styles notation 👩🎤 Supports both
  • 11. So what the possibilities? 🎉 Media queries 🎉 Keyframes 🎉 Pseudo classes 🎉 Nested selectors 🎉 It's JS, so you have all its power 🎉 Babel and Webpack optimisations for production 🎉 Total isolation if old global CSS approach is not used 🎉 Easy theming support
  • 12. So what the possibilities? 🎉 Full interoperability with existent CSS 🎉 Inject global styles if you know what you are doing 🎉 Full support for styling 3rd parties components 🎉 Extend API for easily reuse styles 🎉 react-primitives - React Native, React Sketch, etc. 🎉 Endless of other powerful things that you can come up with
  • 15. 💩 Weak editors support?! It's just strings and objects! 🎉 Nope! Webstorm, VS Code, Sublime Text, Atom support is there! 💩 Formatting! I sure it's just highlights the text, but no formatting! 🎉 Nope! Webstorm formats it perfectly. (Not sure about others though) 💩 Meh! Then I won't use! 🎉 Editors doesn't matter. Prettier is formatting CSS in template literals ;) 💩 But we don't use it! 🤖♀️ What's wrong with you?! It's amazing! 💩 I'm not impressed yet..... I need something. It's stupid to have CSS in JS! 🤷♀️ Okay, but what did you were saying about JSX a few years ago 🤖 💩 PERFORMANCE!
  • 16. Well, you are a little correct 💩 💩 styled-components performance in unrealistic benchmarks is very weak 🎉 Good news. Emotion and glamorous have bench performance only 5-10% slower than CSS Modules 🎉 Real world apps performance is good for all solutions 🎉 There is a hacks to improve it even further if so needed
  • 17. So, what you would recommend? styled-components 💅
  • 18. Why? 💅 11000 stars on GitHub, means lots of contributions 💅 Supports React Native and other renderers 💅 Amazing Jest and other test runners support 💅 A lot of tooling is already done for it 💅 Stylelint support (works for emotion as well) 💅 The best documentation 💅 Better performance - matter of time
  • 19. Future of CSS-in-JS 🤖 ISTF - Interoperable Style Transfer Format (Even further performance improvement, CSS-in-JS styles interop) 🤷 Extreme styles optimisations to reduce amount of CSS code up to 30-60% (depends on codebase size)
  • 20.
  • 21. That's all folks! 👋 GitHub: RIP21 Twitter: @RIP212
  • 22. List of links and resources 🔗 • Sandbox for this speech • A unified styled language @markdalgleish - MUST READ (pick on CSS-in-JS by co-author of CSS Modules) • styled-components documentation • emotion documentation and full of perf demos of emotion in its authors twitter • glamorous documentation • Amazing article about styled-components future and CSS-in-JS in overall by one of the authors of s-c • Template string literals or Object notations, what to choose? Read that