Styled Components Is the Only Way To Do CSS

  Рет қаралды 21,217

Engineer Man

Engineer Man

2 жыл бұрын

Styled Components is the way forward for component styling. After using LESS, SASS, and SCSS, I can say this is the best tool for React and React Native projects.
Hope you enjoyed the video!
Check out this code here:
github.com/engineer-man/youtu...
Join my Discord server and come say hi:
/ discord
Check out some code on my GitHub:
github.com/realtux
github.com/engineer-man/youtube
Send me a Gab:
gab.com/engineerman
Other Social:
/ engineerman
/ _engineerman
/ engineermanyt
www.flaticon.com/free-icons/tick - Tick icons created by Octopocto - Flaticon

Пікірлер: 78
@tobias-edwards
@tobias-edwards 2 жыл бұрын
CSS scoping can be handled with CSS modules, not just styled-components. Scoping styles to a human-readable wrapper class, as shown in your SASS example, is fragile because you may still cause a name collision and every component is now required to have a wrapper class to scope it's inner styles. I'm not fully convinced of styled-components because: a) it mixes CSS and JS which is not modular and it's React-only syntax. tech changes all the time and it'll be harder to separate the two b) it mixes CSS and JS AND HTML: you specify the HTML tag as part of the styled-component which adds another abstraction layer and makes it harder to read e.g. imagine you're reading JSX and you see , ok so it's a header tag, right? Actually it could be a header, h1, h2, h3, p, etc. and the developer is forced to dig an extra layer to find out what is the semantic tag EDIT: logically incorrect and clickbait video title, don't sink to the level of shitty devs on KZbin. I usually like your videos, keep it up :)
@karl4813
@karl4813 Жыл бұрын
I 100% agree, never really saw the point of styled components, why would I want to scroll 500 lines of CSS code before arriving at JS/JSX logic lol
@CodeWithKenny
@CodeWithKenny Жыл бұрын
No, you just have to define a parent tag of a page, then grab the rest of the tags normally like you would using their ID's and classes.
@ricardo.mazeto
@ricardo.mazeto 2 жыл бұрын
I find it absolutely amazing how JavaScript developers always find an way to justify a bad idea.
@lynn_phoenix
@lynn_phoenix 2 жыл бұрын
Absolutely not. This was the case 3-4 years ago. Then we as a community learned styled-components is a major source of performance issues with re-renders and js execution time. If your code is SEO vital, styled components is going to harm you for Core Web Vitals. You are much better off with CSS Modules and/or Tailwind.
@_justnick
@_justnick 2 жыл бұрын
^ yup, on react native projects maybe yes, but web it's just not as worth it
@pierrelucas3784
@pierrelucas3784 2 жыл бұрын
Do you have a link to explain the downsides please ?
@kart1372
@kart1372 Жыл бұрын
I'm a newbie , so can you explain further? Aren't styled components rendered only when needed? How does that harm the web vitals? For a big project should we use CSS or Styled components?
@JMIK1991
@JMIK1991 Жыл бұрын
@@kart1372 It renders each time new component is found in the code and pauses current process to do it. So it requires longer load time and the site becomes extremely heavy the more you depend on it. Though I think there was a way to delay or preprocess the rendering final product... Like html has preloading for images or other files as if they are part of background process. React server -> pages -> page change, process at pc or ask server for component changes -> repeat until all loaded. Basically on older pc you see white screen flash and components move in order as the page continues to load. It still takes longer than a static page rendering with browsers. Normal html, css and no js executions to change content. I'd rather ask the information for preview from server. Rather than ask how it is previewed and then ask for the information. I did some react, I prefer static pages, but it was fun doing a point calculator for card game with component attributes. I cant say it is a waste to learn react as you can think a way to do it with other type of js script later, like by simply search and access elements, which to fill with the new information, using just normal js.
@DSCuber
@DSCuber 2 жыл бұрын
The company I just started at uses these for our product and I'm glad you made a video on this! I was wondering where the funky class names were coming from, I figured it might've been something with our bundler.
@johnc0de
@johnc0de 2 жыл бұрын
Amazing video!< This helped a lot!
@vivekkaushik9508
@vivekkaushik9508 2 жыл бұрын
Very apt and informative video. Thanks.
@conspirisi
@conspirisi Жыл бұрын
Really nice concise explanation.
@bbrendon
@bbrendon 2 жыл бұрын
Seems handy but what is React and React Native?
@twicegravity
@twicegravity 2 жыл бұрын
I would love to see a more in depth tutorial about styled components from you. But in the several videos I've watched trying to learn it, I learn more from you than all those other videos and in only 7 minutes
@ZacKoch
@ZacKoch 2 жыл бұрын
Eh - it's neat but I think I'd prefer creating class selectors in the stylesheet... I imagine what you've shown would be useful for small projects, but what if a big team is working on this? They'd have to find all the little places where you've created the consts if they want to change the styling. Thank you for showing us as always, and great video!
@EngineerMan
@EngineerMan 2 жыл бұрын
Bear in mind this is a React only solution anyway. In a normal React project, components are their own files (usually). So changing component style just means opening the file and changing it. The strength of this is bigger as the team size grows.
@KnThSelf2ThSelfBTrue
@KnThSelf2ThSelfBTrue Жыл бұрын
I think the key here is separation of component libraries and themes from frontend application code. You want that single global profile layout style, and you don't want to go find and change all 1000 individually styled buttons with a duplicated font size attirbute, but at the same time, every consumer of your library will have its own unique complexity, so you probably can't account for everything in your component library, and ad-hoc styling is a must. As long as those two things are separate, you dodge the maintenance overhead of defining styles on a component-by-component basis and get the best of both worlds.
@Svidur
@Svidur 2 жыл бұрын
One question, the problem with specificity is not solved with css modules? I'm using emotion usually (it's basically almost the same as styled components), but i always wondered if the approach with css modules would solve the same problems and it's css by default so it's easier to disattach from the js file (if the component is too large sometimes it's better to separate styles in another file i think). You could create another file for the styles in js but it's strange for me. Great video by the way!
@theonlyD
@theonlyD 2 жыл бұрын
100% of the times specificity issues arise from overuse of frameworks and bad factoring of components.
@hakobtorosyan7413
@hakobtorosyan7413 Жыл бұрын
I wanted to find the “props” thing like 2 hours. Thank you
@khaledsaidi7709
@khaledsaidi7709 Жыл бұрын
For those who liked the idea of css-in-js and think it's not possible for a framework like Angular. You could use emotionjs which is a css-in-js library that is framework agnostic. 🔥
@tomcrooks1627
@tomcrooks1627 2 жыл бұрын
Since giving tailwind a try, I don't think i'll ever look back. 😊
@fuzzylogic33
@fuzzylogic33 2 жыл бұрын
With inline fold
@radomane
@radomane 2 жыл бұрын
Ported over every component in a large project to tailwind from styled components, and it’s so much nicer.
@0xTomster
@0xTomster 2 жыл бұрын
Facts!
@alexnezhynsky9707
@alexnezhynsky9707 2 жыл бұрын
Same, global css utility classes are the way to go. Just need locally scoped css sometimes, a-la vue or svelte all-in-one file with style tag
@irun_mon
@irun_mon Жыл бұрын
I really want to use tailwind but we only allowed to use boostrap at work, so boring 😩
@CrzyMan_Personal
@CrzyMan_Personal 2 жыл бұрын
While I'm not a fan of React, styled components are beautiful and I will do everything in my power to keep using them.
@olatunjiolakunle6908
@olatunjiolakunle6908 Жыл бұрын
vue sfc addresses some of the issues with the scoped style tag.
@acidhauss7018
@acidhauss7018 2 жыл бұрын
I'm not 100% convinced but I might try using it for a few small components and see how I get on - cool video nonetheless
@KyleBeard
@KyleBeard 2 жыл бұрын
Definitely recommend tailwind over styled components, but definitely styled components over raw css or scss.
@highlanderdante
@highlanderdante 2 жыл бұрын
Tailwind > CSS modules >>>>> styled components IMHO.
@gamer-tantrik
@gamer-tantrik 2 жыл бұрын
using Tailwind with classnames (an npm package because Tailwind doesn't conditionally renders classes) is a perfect choice.
@MarkAnthony819
@MarkAnthony819 2 жыл бұрын
IMHO...styled components are more segregated in the code and have more "readability" for those who are old time CSS people. 1/styled components, 2/tailwind. Thanks
@Nellak2011
@Nellak2011 Жыл бұрын
Tailwind is a pleasure to write, but not to read. It also lacks the features that makes Styled Components great like the ability to make extensible design systems. Tailwind is good for prototyping and small projects that don't change much, but horrible for use on a real team.
@gamer-tantrik
@gamer-tantrik Жыл бұрын
@@highlanderdante true
@chefmaniafgc
@chefmaniafgc 2 жыл бұрын
TailwindCSS wants to have a word with you
@betterfly7398
@betterfly7398 Жыл бұрын
5:18. Glad to know I am not the only one who says "and and" lol.
@mingirc
@mingirc Жыл бұрын
Appreciate the video. But why not using sass as module? It is solving all sass/css downsides mentioned in this video and also giving same or more flexibility with less boilerplate and also with a very less learning curve. In addition to that, Styled Components also creating a conflict with the props usage as you would be using the props both passing the react props and also styles components props.
@rAskRedditHighlights
@rAskRedditHighlights Жыл бұрын
How do you click on links that are obviously malicious, but without getting hacked? Like in your punishing scammers video. Keep up the great content :)
@gamer-tantrik
@gamer-tantrik 2 жыл бұрын
Hey Engineer man just use Tailwind with *classnames* npm package. It is much more powerful and useful than styled components.
@theretroman3862
@theretroman3862 2 жыл бұрын
Vue 3 has just about the same logic but more more eloquent, and minus the spaghetti code React ends up beying.
@xphstos_
@xphstos_ Жыл бұрын
Styled components is a great solution, way better than Tailwind... I can't see why people are so into that trend. Tailwind is for people that don't really care about CSS much. Anyway.. I would prefer to have a separate file for my styles but it's doable with styled components and I like that you can easilly pass props and use them directly in your rules. Although, you can do the exact same thing with CSS Modules and you can pass the "props" as classes or CSS variables. Plus you can use SCSS in your modules... so many nice color functions mixins etc. (I know there is polished for styled components). I also happen to prefer the class naming in CSS modules, way more friendly in the eye. CSS modules and Styled Components they have some similarities and recently vanilla extract css kinda merged those worlds and by the of Greysk... eehh sorry I mean Typescript we get to have a typed version of CSS Modules.. pretty neat. To be honest though in most of my projects, CSS Modules seems the right way for me.
@postingbmwm3
@postingbmwm3 2 жыл бұрын
Tyrone agrees with Engineer Man.
@luissolanodev
@luissolanodev 2 жыл бұрын
Engineer man was living under a rock and just discovered styled components😆 jk
@EngineerMan
@EngineerMan 2 жыл бұрын
Lmao. I started using React and then MUI. My old way of styling seemed less and less appropriate.
@PrevalentAA
@PrevalentAA Жыл бұрын
​@@EngineerMan React, MUI and styled components are probs one of the best matches out there. Super powerful, reliable, robust throughout the whole codebase regardless how large, and a delight for the developer writing/reading the code. Have not encountered a single thing I couldn't do with these things, throw formik and yup in the mix as well for clean and robust form handling.
@UmeshGupta-hq4yo
@UmeshGupta-hq4yo Жыл бұрын
Can you help me please
@yakob-g
@yakob-g 2 жыл бұрын
i prefer tailwindcss, so efficient
@vivekkaushik9508
@vivekkaushik9508 2 жыл бұрын
I like it too. Just takes a little bit of time to setup and learn the apis.
@codeaccuna
@codeaccuna 2 жыл бұрын
@@vivekkaushik9508 intellisense vscode extension ftw
@McDevil1988
@McDevil1988 2 жыл бұрын
Personally I would not use React, because its way to complicated.. Svelte is the way to go, including Tailwind CSS and you have the perfect setup nowadays
@nunu_blot1063
@nunu_blot1063 2 жыл бұрын
I thought tailwind was deprecated and out of date
@chefmaniafgc
@chefmaniafgc 2 жыл бұрын
@@nunu_blot1063 It is the complete opposite. The support for Tailwind is massive and the JIT integrations makes the setup extremely simple
@theonlyD
@theonlyD 2 жыл бұрын
In the end it's the same shit and just a different way to do it. This makes sense when working with a JS framework but it's lame to claim that this is "the only way to do CSS" where for most projects this is just cruft.
@jackflowt
@jackflowt Жыл бұрын
Unfortunately this new trend of css in js can destroy the performance of your application especially in android mobile devices.
@jackflowt
@jackflowt Жыл бұрын
We experienced this first hand on our website. Styled components causes high LCP, ergo taking huge hits on SEO.
@jackflowt
@jackflowt Жыл бұрын
The idea was doomed from the start, JS performance on mobile devices is very poor especially on Android devices. You're better off by using vanilla css modules. Don'tforget that Google crawlers use the mobile view to benchmark your website! Not surprising since 70% of web traffic are from mobile devices, and this number will continue to grow.
@emreozgun3846
@emreozgun3846 Жыл бұрын
@@jackflowt 50% of the web traffic comes from mobile devices not 70%.
@MrPoselsky
@MrPoselsky 2 жыл бұрын
I don't fully agree. Can imagine when you're doing SPA stuff then this makes a lot of stuff easier but what happens then if you need to share these styles with other part of your system outside React? Let's say admin page runs on react but main page can be SSR generated. If your only reason is because of maintainability, then that's what tests are for.
@v1d300
@v1d300 2 жыл бұрын
SC does has a way to create GlobalStyles too. So your variables and global CSS styling can go in there.
@uiytt8497
@uiytt8497 2 жыл бұрын
Svelte also support this, very useful
@dzhimy6266
@dzhimy6266 2 жыл бұрын
Good thing I don’t have brain damage (write JavaScript) then.
@Gigusx
@Gigusx 2 жыл бұрын
I've always preferred writing my own CSS over using styled components-like libraries. Now with Tailwind it's not even a competition.
@blehbleh9283
@blehbleh9283 2 жыл бұрын
No it's tailwind. JK good video
@anridev24
@anridev24 Жыл бұрын
I do not recommend "Styled Components" today there are many alternatives which offer much better developer experience and performance.
@brahmabull4004
@brahmabull4004 Жыл бұрын
List em
@paulydee5650
@paulydee5650 Жыл бұрын
@@brahmabull4004 css modules
@60RPM
@60RPM Жыл бұрын
Styled components are the worst idea developers have ever come up with. Time for this stupid fad to end
@hellboy6167
@hellboy6167 Жыл бұрын
Tailwind is best than this approach
@CapeSkill
@CapeSkill 2 жыл бұрын
what's with all these clickbait titles nowadays.
Git Good: Team Development
13:03
Engineer Man
Рет қаралды 14 М.
Why you should look into these React component styling options!
27:17
He sees meat everywhere 😄🥩
00:11
AngLova
Рет қаралды 11 МЛН
Nutella bro sis family Challenge 😋
00:31
Mr. Clabik
Рет қаралды 12 МЛН
Самое Романтичное Видео ❤️
00:16
Глеб Рандалайнен
Рет қаралды 5 МЛН
Using CSS custom properties like this is a waste
16:12
Kevin Powell
Рет қаралды 161 М.
Engineer Breaks Down Hollywood Programming Scenes
11:02
Engineer Man
Рет қаралды 22 М.
Styled Components & React ПОЛНЫЙ КУРС
23:40
Ulbi TV
Рет қаралды 66 М.
Why I Pick ShadCN and Tailwind for all my projects
18:53
developedbyed
Рет қаралды 57 М.
Difficult Programming Concepts Explained
11:13
Engineer Man
Рет қаралды 68 М.
How Major Parts of Modern Software Fit Together
12:12
Engineer Man
Рет қаралды 22 М.
This is the Only Right Way to Write React clean-code - SOLID
18:23
Why Signals Are Better Than React Hooks
16:30
Web Dev Simplified
Рет қаралды 461 М.
Svelte UI Libraries Have Leveled Up
12:14
Huntabyte
Рет қаралды 55 М.
iPhone 15 Pro в реальной жизни
24:07
HUDAKOV
Рет қаралды 41 М.
В России ускорили интернет в 1000 раз
0:18
Короче, новости
Рет қаралды 1,8 МЛН
Simple maintenance. #leddisplay #ledscreen #ledwall #ledmodule #ledinstallation
0:19
LED Screen Factory-EagerLED
Рет қаралды 27 МЛН
Samsung Galaxy 🔥 #shorts  #trending #youtubeshorts  #shortvideo ujjawal4u
0:10
Ujjawal4u. 120k Views . 4 hours ago
Рет қаралды 2,7 МЛН