Class Central is learner-supported. When you buy through links on our site, we may earn an affiliate commission.

YouTube

Why I Don't Use Margin in React Components

ByteGrad via YouTube

Overview

Coursera Spring Sale
40% Off Coursera Plus Annual!
Grab it
Learn why avoiding margin in React components leads to more maintainable and reusable code through this 11-minute tutorial. Explore common anti-patterns where developers apply margins directly to components, making them less flexible and harder to reuse across different contexts. Discover two practical solutions for handling spacing: using wrapper elements and implementing utility classes with the cn function. Examine real-world examples including buttons and cards to understand when margins create problems and how to refactor components for better composition. Understand the differences between margin, padding, width, and height properties in component design, and master best practices for creating truly reusable React components that don't dictate their own positioning.

Syllabus

00:00 Example of the anti-pattern
02:12 Solution #1
03:01 Improve skills
04:08 Solution #2 cn
05:47 Button with the anti-pattern
06:27 Solution
06:59 What about padding?
07:30 What about width / height?
08:09 Card with the anti-pattern

Taught by

ByteGrad

Reviews

Start your review of Why I Don't Use Margin in React Components

Never Stop Learning.

Get personalized course recommendations, track subjects and courses with reminders, and more.

Someone learning on their laptop while sitting on the floor.