Why I Don't Use Margin in React Components

Why I Don't Use Margin in React Components

ByteGrad

2 месяца назад

14,704 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@j.n.r.6464
@j.n.r.6464 - 20.11.2024 04:11

I do love using the gap property with flexbox, but it's not supported by Safari 14.4 which had its last release in 2020. It's surprising how many customers are still using this version.

Ответить
@ruslansergazin8239
@ruslansergazin8239 - 15.11.2024 02:51

Why we cant use just these for class names merging? It is literally 2 string. ["your classname", "other default classnames"].join(' ');

Ответить
@yongkuannn
@yongkuannn - 15.11.2024 02:43

I'm interested in the course but didn't receive any reply for 2 days on Crisp. Is the currency based on location or USD by default? Because it is currently taxed according to my country. And are there any promo codes to use on the checkout page? And will the course be updated to Next 15 and its future releases?

Ответить
@juliusgrisette
@juliusgrisette - 14.11.2024 20:17

Thanks for the cn tip

Ответить
@MrZerosixZeroone
@MrZerosixZeroone - 14.11.2024 11:27

React will be dead in 3 to 5 years.

Ответить
@jarekceborski
@jarekceborski - 14.11.2024 00:42

exactly why I prefer styled-components

Ответить
@uixmat
@uixmat - 13.11.2024 19:14

Love your videos but genuinely think this is not the best solution (specifically regarding the h1) and is actually an anti-pattern in itself. You're using Tailwind so simply add a global class and use @apply utility from tailwind allowing you to have a global style for all your headings without the additional engineering to simply add another class. But all that said; for card components etc is spot on - apologies if this comes across overly critical x

Ответить
@userj-s2000
@userj-s2000 - 13.11.2024 11:03

Just make a component for a component for a component, now thats a pattern

Ответить
@AnthonyPaulT
@AnthonyPaulT - 13.11.2024 09:32

Your whole video is an antipattern. You don’t want to add className to your reusable components

Ответить
@codokit
@codokit - 13.11.2024 02:51

Better create traditional class “title” and use tailwind @apply.

Ответить
@brianmeyer3050
@brianmeyer3050 - 13.11.2024 02:32

🚨 Your demonstration is actually the anti-pattern. 🚨 Leverage the core features of the CSS Cascade, and create global styles for core elements (which your browser already does). Custom components for basic styles creates a ton of code cruft, and makes editing the core attributes of those elements impossible without building out an entire interface.

Ответить
@videoponder4673
@videoponder4673 - 13.11.2024 02:27

Instead of cn function, it is possible to simply write: <p className={"font-bold " + className}>. It is just important that the string ends with a space.

Ответить
@lorisquesado6468
@lorisquesado6468 - 13.11.2024 00:08

Hey ! One of the thing I often see regarding typescript is in fact typing each prop like : className?: string, children: React.ReactNode.

But those prop already exists and it can be tedious to add those like that, I highly recommand using this pattern instead:

(if I take your example title component)

const H1: React.FC<React.ComponentPropsWithoutRef<"h1">> = ({className, ...props}) => <h1 className={cn("some-default-classNames", className)} {...props} />

I know it may be strange to see and orphan tag spreading props like that but children is part of {...props} and will be evaluated as a React.ReactNode, It makes it super flexible and it inherits the native h1 props.
Therefore, we could send a data-anyattribute or other basic aria elements etc. to our generic component.

I don't know if you've alreay covered this approach into another video but just in case you don't, it could help others to know this :)

Anyway, your videos are great ByteGrad, I love your content, thank you very much ! 🤗

Ответить
@wolfie8748
@wolfie8748 - 12.11.2024 23:37

which vs theme are you using?

Ответить
@dangray5809
@dangray5809 - 12.11.2024 23:25

Always a good choice to watch a ByteGrad video!

I already knew most of this stuff having taken the React/Next course, but low and behold, I've been using space in conjunction with flexbox! Time to start using gap instead.

Ответить
@MrEnsiferum77
@MrEnsiferum77 - 12.11.2024 23:09

Everything is antipattern in react, nothing is scalable on big project.

Ответить
@friedricht3908
@friedricht3908 - 12.11.2024 20:23

I ditched all margins from my code base because everything that can be done with margin can be done with padding and flexbox

Ответить
@OP-ig1fj
@OP-ig1fj - 12.11.2024 17:29

just create typography.tsx with variants using class-variance-authority

Ответить
@Volodymyr-y1c
@Volodymyr-y1c - 12.11.2024 16:52

The biggest anti-pattern in React is to add className prop to your components. Looking at title of the video, I was genuinely hoping you were gonna tell about it.

Ответить
@azizoid
@azizoid - 12.11.2024 15:44

I prefer using pure css for the page template, if style is the only change for my custom component

Ответить
@stavroskefaleas6320
@stavroskefaleas6320 - 12.11.2024 14:55

We want a tanstack start course please!

Ответить
@crackier2934
@crackier2934 - 12.11.2024 14:39

This is awesome you can also make the className prop optional by adding a ? on its type className?: React.ReactNode if you want it to have default styles in some places.

Ответить
@kashmirtechtv2948
@kashmirtechtv2948 - 12.11.2024 14:32

we need such videos

Ответить
@VLADICA94KG
@VLADICA94KG - 12.11.2024 14:30

Great video nobody talks about! Thanks!

Ответить
@Sahil.1
@Sahil.1 - 12.11.2024 13:35

Title made me google anti pattern as non native speaker 😂

Ответить
@mzerone-g6m
@mzerone-g6m - 12.11.2024 13:24

For cards use subgrid

Ответить
@mzerone-g6m
@mzerone-g6m - 12.11.2024 13:23

I think the biggest and anti-pattern the people forget to use forwardref

Ответить
@shis10
@shis10 - 12.11.2024 13:09

Amazing video

Ответить
@squarerootof2
@squarerootof2 - 12.11.2024 12:17

There is also a similar very small utility called "clsx" to conditionally apply class names

Ответить
@ManishGupta-nv5by
@ManishGupta-nv5by - 12.11.2024 11:21

Start with reusable Tailwind classes for simple styles.
Gradually migrate to reusable React components as complexity increases.
.H1 {
@apply text-5xl font-bold;
}

.H2 {
@apply text-3xl font-semibold;
}

.body-text {
@apply text-lg leading-relaxed;
}

Ответить
@fluntimes
@fluntimes - 12.11.2024 11:09

Styled Components. My goto solution for global and scoped styling. Tailwind is great but I'm finding more and more that companies hiring want developers who can use CSS design systems, including SASS, modules, and BEM.

Ответить
@prohacker5086
@prohacker5086 - 12.11.2024 10:54

I'm in love with your videos, it's just so damn organized and easy to understand. I hope you get to explain other programming frameworks like this too. Be it React Native, .NET, Django, Java Spring. I would watch any video you upload as long as you explain the very fundamentals and the correct pattern to adopt, because it is satisfying.

Ответить
@ParaZumir
@ParaZumir - 12.11.2024 10:51

Ответить
@devnemo
@devnemo - 12.11.2024 10:11

Great

Ответить
@techiesakar
@techiesakar - 12.11.2024 10:03

I always do the same. And it is quite helpful.

Ответить