Two Ways to Write Cleaner Components

  Рет қаралды 29,284

LearnVue

LearnVue

Күн бұрын

Пікірлер: 57
@alexmorris5019
@alexmorris5019 2 жыл бұрын
This is adding indirection, declarative templates are so much easier to read. Imagine if there was an easy way of applying styles to all anchor tags inside a given div. Oh, wait..
@GoWokeGoBroke1
@GoWokeGoBroke1 Жыл бұрын
Agreed. This is terrible. In my case I would definitely not approve this PR and demand a rewrite
@LosfrogerX
@LosfrogerX Жыл бұрын
Yeah, this could be solved with some css, and if you're using tailwind, maybe with the @apply thing to get your tailwind classes
@ScimonInTheSkies
@ScimonInTheSkies Жыл бұрын
Could you elaborate maybe on functional components having props, using typescript (even with setting optional and default props)? :)
@alnahian2003
@alnahian2003 Жыл бұрын
I kinda feel guilty of using for loops everywhere now 😅 Nice tips, Jake
Жыл бұрын
Does Tailwind compiler pick up these classes in the render function?
@JaimitoAleman
@JaimitoAleman 2 жыл бұрын
Without fail ALWAYS the GREATEST CONTENT @matt 🙂😎👍
@shareefhassan8197
@shareefhassan8197 2 жыл бұрын
I really love the render function approach, are there any reason why it maybe a bad thing? i feel like they wouldn't benefit from the same compile time optimizations that vue does unlike normal components
@kasopejohnson3831
@kasopejohnson3831 2 жыл бұрын
Maybe not but if it's used for small content components like it is here it probably doesn't need much optimisation. It's just returning vnodes
@RedsTom_
@RedsTom_ 2 жыл бұрын
For your own sanity, I recommend you use tsx or jsx to return content in these functional components instead of the render method
@plukerpluck
@plukerpluck 2 жыл бұрын
First video I'm seeing from you, but this seems like some real good content! I've just started messing with tailwind myself, and it's clear to me that the entire concept of tailwind feels based around the fact that we can remove repetition though alternative methods (components and loops) and because of that we can "inline" our styles again. Yet all examples never seem to take advantage of that! I've never really used the render function, so seeing it used as a way to make tailwind even better is great! It makes perfect sense for those tiny components where it feels overkill to create a new file. Will definitely be checking out your other videos.
@RedsTom_
@RedsTom_ 2 жыл бұрын
Imho the render function is a bit weird. I personally prefer using tsx or jsx. In this way, functional components really feel like you're using react 😂. Speaking of tailwind, this is clearly a bad framework in my opinion as you're doing all your CSS in the classes instead of in the stylesheets...
@plukerpluck
@plukerpluck 2 жыл бұрын
@@RedsTom_ The question you should be asking about tailwind is this. Why use stylesheets instead of inline styles? What is wrong with inline styles? Because that's the purpose of tailwind. Tailwind says "inline styles are cool but a bit too verbose and not powerful enough". Think of it like that, and perhaps you'll see why some people love it.
@RedsTom_
@RedsTom_ 2 жыл бұрын
@@plukerpluck because inline styles are pure shit. You can't reuse the same on two elements without rewriting the whole thing, it's horrible to determine what belongs where, it's a pure nightmare to debug and more important : it's ugly as fuck. Stylesheets weren't invented for pure pleasure but because they are necessary. Return to html4 if you want to use inline style, you'll be happy with what existed
@paulvarner9570
@paulvarner9570 Жыл бұрын
@@RedsTom_ Tailwind is great for ameliorating cognitive shifting during development. You can then extract it to sass, assign whatever naming conventions you want, and clean up your components when closer to production.
@paulvarner9570
@paulvarner9570 Жыл бұрын
@@BeFourCM 'Reusing Styles' on TailwindCSS docs. If extracting is done prematurely during development, it just adds confusion; but when components are fairly locked in, then extract. If you need to override a style down the road, then pass to component as attribute.
@mjbates7
@mjbates7 2 жыл бұрын
How would you go about doing functional components with typescript? Ie what types does the function need to take etc. Be useful to see how to do it with both js and TS. Cheers
@RedsTom_
@RedsTom_ 2 жыл бұрын
Use tsx as the lang and return html. It will look a lot like react and will be really apreciable to use
@arthur10renato
@arthur10renato 2 жыл бұрын
Thank you for one more awesome video!
@LearnVue
@LearnVue 2 жыл бұрын
thanks for watching
@ДенисКуликов-м3о
@ДенисКуликов-м3о 2 жыл бұрын
Vue 3 имеет дополнительную оптимизацию шаблонов в отличии от функций рендеринга. (translate) Vue 3 has additional template optimizations as opposed to render functions.
@brunolopes_
@brunolopes_ 2 жыл бұрын
Sounds good! But decrease the legibility. Like all things in T.I, it's a tradeoff.
@MuhammadM1998
@MuhammadM1998 2 жыл бұрын
This is nice. Thanks for the great work. Please consider doing more Nuxt content now it's stable (maybe a seperate channel if possible?)
@LearnVue
@LearnVue 2 жыл бұрын
have some nuxt content coming soon on this channel!
@MuhammadM1998
@MuhammadM1998 2 жыл бұрын
@@LearnVue This is great your content is amazing much thanks 🙏
@starlederer
@starlederer Жыл бұрын
I wonder why you didn't talk about the simplest and most obvious method: put these classes in a string and reuse it
@JoachimEckerlin
@JoachimEckerlin 4 ай бұрын
You mean like having a single class and adding css properties to it? 😅
@whaaaley3810
@whaaaley3810 9 ай бұрын
Functional components is the primary reason I love using JSX in Vue rather than templates.
@kirillvoloshin2065
@kirillvoloshin2065 2 жыл бұрын
looks wild from a react dev perspective
@kevinison3740
@kevinison3740 Жыл бұрын
Good videos... background music is distracting...
@iq240-1
@iq240-1 2 жыл бұрын
Awesome 👍
@fayazara
@fayazara 2 жыл бұрын
Love your content
@RedsTom_
@RedsTom_ 2 жыл бұрын
Best way to clean up tailwind mess : don't use tailwind
@cotneit
@cotneit 2 жыл бұрын
Just don't overabstract things, one of the selling points of Tailwind is how easy it is to make changes, needless abstractions mess with that
@Mark73
@Mark73 Жыл бұрын
Why would nested loops be a red flag?
@СергейКиршевский
@СергейКиршевский 2 жыл бұрын
Or... you could just use @apply
@RedsTom_
@RedsTom_ 2 жыл бұрын
Or just write plain css
@christianmartinez2179
@christianmartinez2179 Жыл бұрын
Every time I see someone use tailwind just to end up pretty much creating a class of classes I get so fucking triggered, don't use tailwind, use normal css and stop adding unnecessarily complicated layers of abstraction just because you feel obligated to use that library
@Natewhar
@Natewhar 2 жыл бұрын
this is literally firesihp with a different voice
@anj000
@anj000 Жыл бұрын
I really despise render function and jsx way of doing this. It is making code so much more complicated and hard to follow.
@arturpendrag0n270
@arturpendrag0n270 2 жыл бұрын
Can you please change your background music. I feel like its distracting from the video at least for me and the sounds are kind of stress inducing.
@Ab4kus
@Ab4kus 2 жыл бұрын
If barely audible background piano music induces stress, don't you think that's something you have to deal with, instead of the person playing it?
@arturpendrag0n270
@arturpendrag0n270 2 жыл бұрын
@@Ab4kus it is barely audible for you but imagine someone with ok headphones that only listens it gets distracting if you are trying to understand with that annoying background piano. Also if you think barely audible sounds aren't stress inducing try looking into the science behind scary movies music and soundtracks.
@ennioVisco
@ennioVisco 2 жыл бұрын
Honestly, better but: 1) you are likely trading worse readability and performances with less repetition (not the best of the trade-offs) 2) CSS/SCSS is still much clearer and can allow developers to define their own "language", it's not that great that we all force ourselves at accepting the assumptions the tailwind people made
@TheMarkDrake
@TheMarkDrake 2 жыл бұрын
The easiest thing to do is not write HTML like this - including dropping the utility-litter-framework (whether it's Tailwind, Bootstrap, or another framework). Write classes via CSS (or SASS) to accompany your web components. If you can't go it alone, leverage the utility-litter-frameworks via SCSS if you have to! There are some good things about the CSS frameworks, but it's best to use only the needed parts.
@pellyryu2344
@pellyryu2344 2 жыл бұрын
Im happy with tons of duplication of tailwindcss and dont want go back to my past days believing css could be separated from html or js at all 😊
@plukerpluck
@plukerpluck 2 жыл бұрын
The whole purpose of tailwind is the realization that CSS separated from HTML is actually really hard to maintain. You need to keep this deep context of where classes are used and how they all interact, and you have to jump back and forth between CSS and HTML to work out what's going on. There's a reason there's so many different "best practices" when it comes to how to handle nested divs and their interactions. Instead we recognise that we can (and should) be creating components for reusable HTML blocks. That's the real way to reduce duplication. And at that point they're effectively solving the same things that functions do in a programming language. And if we're using components properly, then why can't we go back to using inline styles? Why can't we couple our style to the HTML (which is, in practice, always heavily coupled anyway) Now, of course, there are edge cases. I wouldn't be against just writing a custom class for these tiny links as an exception. That's especially true given that you can use `@apply` to actually use the tailwind classes in your custom CSS.
@RedsTom_
@RedsTom_ 2 жыл бұрын
@@plukerpluck but with Vue, CSS is with html, just a couple lines underneath. No need for a heavy framework for the developer (because yes, tailwind is ultra heavy visually) to write and maintain CSS. And if you are too bad to do this, quit, it's not your job to write frontend uis.
@IanJamieson
@IanJamieson 2 жыл бұрын
I f*cking hate tailwind. I keep seeing people littering front end code with this utility class mess. Create components and your styles. Learn to create your own design system. It's bootstrap 2022.
@plukerpluck
@plukerpluck 2 жыл бұрын
@@IanJamieson The whole point of tailwind is simply the idea that "inline styles are actually a good idea, but wouldn't it be great if we could make them practical". It's not really similar to bootstrap at all. And when your CSS classes are so simple, it makes sense for everyone to use the same system. That way anyone can glance at your HTML and see what's up. I find it much easier to maintain in practice vs having to context switch between HTML and CSS on a code base you're not familiar with. The only time I'm a little apprehensive about it is if you're running many media queries. But even then you could write regular CSS using `@apply` to use the tailwind classes there as well, allowing you to mix and match if need be.
@i3looi2
@i3looi2 2 жыл бұрын
Not the best case scenario. You simply waste time by compressing all that (mostly static html) into a component. Good practice for own projects and such, but not practical from productivity pov.
How Vue Keep Alive Can Improve Your App
6:45
LearnVue
Рет қаралды 30 М.
My New Favorite UI Library
7:10
LearnVue
Рет қаралды 14 М.
-5+3은 뭔가요? 📚 #shorts
0:19
5 분 Tricks
Рет қаралды 13 МЛН
Wednesday VS Enid: Who is The Best Mommy? #shorts
0:14
Troom Oki Toki
Рет қаралды 50 МЛН
Vue Slots Simplified
7:25
LearnVue
Рет қаралды 57 М.
Dynamic Scroll States with Intersection Observer + Vue
5:41
LearnVue
Рет қаралды 31 М.
Should You Use Vue RENDERLESS COMPONENTS?
4:20
LearnVue
Рет қаралды 22 М.
Vue just got SO MUCH better
4:06
LearnVue
Рет қаралды 43 М.
Pinia Simplified
4:28
LearnVue
Рет қаралды 126 М.
When You SHOULDN'T Use Computed in Vue
4:03
LearnVue
Рет қаралды 28 М.
Better Rendering Performance with Virtual Lists
5:59
LearnVue
Рет қаралды 36 М.
Easy Loading Screens with Vue Suspense Components
4:29
LearnVue
Рет қаралды 34 М.
Tools EVERY Software Engineer Should Know
11:37
Tech With Tim
Рет қаралды 28 М.
-5+3은 뭔가요? 📚 #shorts
0:19
5 분 Tricks
Рет қаралды 13 МЛН