I Never Want to Write Tailwind Any Other Way

  Рет қаралды 38,706

Josh tried coding

Josh tried coding

Күн бұрын

Пікірлер: 58
@MrREALball
@MrREALball Жыл бұрын
Be careful with tw-merge on large or performance sensitive projects. It has a runtime cost in it (obviously). It is significant (and noticable) the first time a variation of classes is presentend and than it gets cached. The best way to mitigate this is to add variants with predefined styles to common components (buttons, inputs, panels, headers, etc.), instead of changing styles with className. A nice library for this is class-variance-authority. At times when you want more flexibility from your components there are 2 additional things you could do: 1. making a custom component-layer classes for common components (like buttons and inputs), that way tailwind would put those declarations before the utility classes, hence the utility classes (basicaly tailwind classes) would always override the relevant parts. 2. use ! (exclamation) when you need to override something, so if you apply additional styles to a button, just put exclamation on before every utility class, that way it would be marked as important. In the cases where performance is not an issue, tw-merge is great, but, not all projects are like that.
@succatash
@succatash Жыл бұрын
U like CVA over CLSX?😊
@SR-zi1pw
@SR-zi1pw Жыл бұрын
Ahh thanks for the info I use tw merge a lot didn't know about runtime
@TheIpicon
@TheIpicon Жыл бұрын
@@succatash they are different things, there shouldn't be a statement "over" something else. clsx is a tool that lets you combine different class names into one string based on some conditions and that's all. cva is a tool that lets you create and manage variants for your components. you should use cva to create your default component variants, and use clsx only in cases you want for some reason to modify those, which most of the time you wouldn't. you can take a look at how shadcn/ui does that, very neat implementation.
@succatash
@succatash Жыл бұрын
@@TheIpicon awesome thanks
@contigen
@contigen Жыл бұрын
Check out tailwind-variants
@walkingin6375
@walkingin6375 Жыл бұрын
I highly recommend the vscode extension HeadWind, which will reorder your CSS or TailwindCSS classes to help maintain a consistent codebase and make things easier overall.
@Veedsify
@Veedsify Жыл бұрын
bro i was just looking up prettier-plugin for tailwind but for some reason it wasnt working, this comment is a life saver
@isaackoz
@isaackoz Жыл бұрын
HeadWind is fine if it's only you working on a project, but if you have a team it's better to use prettier for code consistency between team members. I.E. if another team member doesn't have the extension installed it won't be formatted correctly while prettier will force everyone to follow the same standards.
@luucsss
@luucsss Жыл бұрын
better to use the prettier tailwind extension
@codinginflow
@codinginflow Жыл бұрын
The Prettier plugin for Tailwind is really amazing. I would also mention applying the recommended settings in the TailwindCSS VS Code extension. E.g. enabling autocomplete in strings.
@Fuzbo_
@Fuzbo_ Жыл бұрын
The prettier sort plugin actually just sorts the classes in the order they appear in the CSS file, so it’s easy to see what overrides what. (e.g. using “p-8 pb-0”)
@TheIpicon
@TheIpicon Жыл бұрын
always wondered what's the cn stood for 😂, thought it was a way to promote shadcn
@arshadyaseen4328
@arshadyaseen4328 Жыл бұрын
c: class n: names
@TheIpicon
@TheIpicon Жыл бұрын
@@arshadyaseen4328 he literally told us that in the video
@automioai
@automioai Жыл бұрын
Feel you
@igorbudimir573
@igorbudimir573 Жыл бұрын
It does, his name is Shad ClassNames
@sandeepreddy6247
@sandeepreddy6247 Жыл бұрын
prettier saves lot of time while reading, thank you.
@MrREALball
@MrREALball Жыл бұрын
Also, if you dont use objects and arrays as arguments for clsx (which you shouldn't, since those are slower, trigger more GCs and memory allocations, while offering next to no value in return), a faster alternative is classix. Or a function anyone could write on their own in a few minutes.
@darrachbarneveld9201
@darrachbarneveld9201 Жыл бұрын
This is amazing, thanks a bunch!
@theReal_WKD
@theReal_WKD Жыл бұрын
I'm using SCSS to style my projects. I have a bunch of reusable classes like "content-column" and so on, and for more specific UI I'll just create a custom class, like "product-card_image-wrapper". I like that it keeps my tsx clean with never more than 3 classes per element (most of the time 1 is enough, I very rarely use 3), which is the main thing that is keeping me from using Tailwind. Seeing 3 lines full of classes just burns my eyes. Can somebody please convince me that Tailwind is better and faster than SCSS to style my projects? Is there anyway to avoid the 3 lines of classes just to give basic styling to an element? Given that all my reusable classes are the same for any project I build, they're already in my boilerplate. I keep seeing everybody using Tailwind like there is no other way to add styles. Yet, I can't seem to find a single reason why I would use it. I ended up thinking that people using Tailwind learned to code via tutorials projects where Tailwind was used. So they never really got to write CSS itself. Having Webflow as a background before I started to code made me go through learning "vanilla" CSS. So when I started coding things from scratch, writing my own CSS felt just right. Then I enhanced it with SCSS but I don't feel like Tailwind would be such an improvement to my developer experience. On the contrary, I think it would make it worse. Anyway, somebody to convince me? 😅
@John-Dennehy
@John-Dennehy Жыл бұрын
For those of us that still hate the overly long className lines, I often use the cn() utility you suggest to split the values into groups, i.e. sm:, md: lg: might all be passed as separate parameters to cn()
@TheIpicon
@TheIpicon Жыл бұрын
notice that cn has a huge runtime cost, using it just to make everything more pretty is pretty much a bad practice.
@John-Dennehy
@John-Dennehy Жыл бұрын
@@TheIpicon good to know. I'll keep it in mind, but given how much faster it helps make my development, I might just take the hit in certain less important projects
@mburakerman
@mburakerman Жыл бұрын
omg this is so wrong. you fixed merge conflict but you made debugging harder
@vommir.
@vommir. Жыл бұрын
Great video Josh, I was wondering if you’re planning a video about Vercel Storage Blob? It’s still in beta but seems like a nice solution to store images, videos, etc.
@nomad_swe
@nomad_swe Жыл бұрын
Idk who releases the tw-merge package but the real and proper one is actually named tailwind-merge on NPM, the other one seems to be a random fork. Also, in regards to the prettier plugin the class ordering isn't decided by prettier but by the creators of tailwind, as they are the ones who made the plugin. The prettier team has nothing to do with it.
@krazymeanie
@krazymeanie Жыл бұрын
There's two different packages. No "real" and "fake" one. You can say "official" since the one you're talking about is from the official tailwind team but I'm pretty sure tw-merge existed before the team made their own implementation
@nomad_swe
@nomad_swe Жыл бұрын
​@@krazymeanie Sorry, there seems to be some confusion. My first sentence is about tailwind-merge, which is not made by the official team (there is no official tw-merge implementation). It seems someone has forked this and is distributing it on NPM under "tw-merge" but the original package from the person who actually made it is distributed under "tailwind-merge" on NPM. See the weekly downloads for proof of which one is the real one there. So yes, there might be two packages but one is a random fork and one is released by the person who created the package and did all the work, I know which one i would like to download. My second sentence is about the prettier-plugin-tailwind package, which is official. And my point there was more of a nitpicky one. Josh says prettier decides the ordering but in reality it's the plugin that does (default prettier doesn't re-order classes) and since the plugin is made by the official tailwind team it would be more correct to say they decide it, not prettier. Should've made it more clear my two sentences were unrelated to eachother.
@alexm9104
@alexm9104 Жыл бұрын
I think if you find yourself in a situation where you really NEED tw-merge, it's time to look at your styles and rewrite them. Make component styles more "basic", use variable classes, but avoid tw-merge if you can.
@sibanzboss6705
@sibanzboss6705 Жыл бұрын
I think there is a extention in vs code to order the classes instead of installing a dependencie
@walkingin6375
@walkingin6375 Жыл бұрын
There is, it's called HeadWind
@tanzimshahriar
@tanzimshahriar Жыл бұрын
Thanks for the video Josh. I am wondering, how do you get the gzipped size on your imports?
@GamingClubGermany
@GamingClubGermany Жыл бұрын
Great Video and nice Tips! But one Problem i struggle with is that its gets really messy after a while and you have a Lot of classnames. Especially when you use Breakpoints like md:. Ist there a solution so Bring more Overview or even move the Styling to abdifferent Location Like Styles components for more Overview or do you have any other Tips to make this more "usuable"?
@michael.knight
@michael.knight Жыл бұрын
That conflict merge setup seems overcomplicated. Also makes it harder to figure out what classes are actually work and what not.
@wojciechosinski5927
@wojciechosinski5927 Жыл бұрын
I was surprised that the border-none was applied. It's opposite of cascading. To me it's huge downside.
@juniorsemerzier660
@juniorsemerzier660 Жыл бұрын
Hello @josh!! how to generate pdf file using Nextjs 13?
@semicolon6499
@semicolon6499 Жыл бұрын
You can you node js also
@sallehshah
@sallehshah Жыл бұрын
Josh, how to setup prettier, eslint, commit lint , best practises for next js 13 with app router.
@ricoaw500
@ricoaw500 Жыл бұрын
function in props isn't that means it will be running everytime?
@zachphilipp786
@zachphilipp786 Жыл бұрын
what is the difference between using your cn functions and just using tw-merge on a component? They seem to do the same thing?
@vitvitvitvitvitvitvitvit
@vitvitvitvitvitvitvitvit Жыл бұрын
clsx is used to handle conditions, wrote in a specific way
@remongrabu
@remongrabu Жыл бұрын
These are great tips but I think the more intuitive way would be to put the incoming className as the first argument in cn() so that you could override the ChildComponent existing styles, so add the red border in this instance
@nickwoodward819
@nickwoodward819 Жыл бұрын
Not a fan of cva any more?
@blazi_0
@blazi_0 Жыл бұрын
I wish there was something like cloning styles in native tailwindcss css. Like you create a button and give it tailwind classes to style it, u also give it classname called btn-primary So when u give another component this classname btn-primary this will be same style as the first button you created Thia feature would be absolutely amazing
@thelukaszns6322
@thelukaszns6322 Жыл бұрын
There is a feature like this! Search for @apply in the Tailwind CSS docs. But AFAIK, it's recommended not to use it in favour of creating reusable components
@michael.knight
@michael.knight Жыл бұрын
That goes against the principles of Tailwind and is really only recommended for edge cases and can be done using @apply. You're better off creating a Button component in React and re-using that, instead of re-using the styles.
@falkfrentzen4120
@falkfrentzen4120 Жыл бұрын
Applying classes conditionally is absolutely awesome using the class-variance-authority library
@abdiastar6451
@abdiastar6451 Жыл бұрын
I cant explain how but you kinda look like erling haaland
@moneyfr
@moneyfr Жыл бұрын
Unocss is way better
@gmkhussain
@gmkhussain Жыл бұрын
Best way to clean up Tailwind mess : don't use Tailwind
@seongminpark3131
@seongminpark3131 Жыл бұрын
so weg... OTL
This new Tailwind feature is scarier than I thought
29:13
Theo - t3․gg
Рет қаралды 61 М.
10 Tailwind Classes I Wish I Knew Earlier
13:31
Web Dev Simplified
Рет қаралды 206 М.
NERF TIMBITS BLASTER
00:39
MacDannyGun
Рет қаралды 14 МЛН
КОГДА БАТЯ ПОЛУЧИЛ ТРАВМУ НА РАБОТЕ😂#shorts
00:59
Шаурма с сюрпризом
00:16
Новостной Гусь
Рет қаралды 6 МЛН
How Did I Not Know This TypeScript Trick Earlier??!
9:11
Josh tried coding
Рет қаралды 221 М.
7 ways to deal with CSS
6:23
Fireship
Рет қаралды 1,1 МЛН
Tailwind-Merge Is Incredibly Useful - And Here's Why!
12:58
simonswiss
Рет қаралды 38 М.
How is this Website so fast!?
13:39
Wes Bos
Рет қаралды 1,4 МЛН
8 TailwindCSS Classes I Wish I Found Earlier
4:48
Tom Is Loading
Рет қаралды 79 М.
Everyone's Making Fun of Next.js 14.0
7:16
Josh tried coding
Рет қаралды 135 М.
TypeScript Generics are EASY once you know this
22:21
ByteGrad
Рет қаралды 150 М.
cn() - Every Tailwind Coder Needs It (clsx + twMerge)
7:46
ByteGrad
Рет қаралды 139 М.
Tailwind V4 Is Bigger Than Expected 👀
20:07
Theo - t3․gg
Рет қаралды 126 М.
Updates Like These Make Tailwind So Fun
8:00
Josh tried coding
Рет қаралды 75 М.