...

/

Manageable Styling for Reusable Components

Manageable Styling for Reusable Components

Let's style our expandable component in this lesson!

Love it or hate it, styling (or CSS) is integral to how the web works.

While there’s a number of ways to style a React component - and I’m sure you have a favorite - when you build reusable components, it’s always a good idea to expose a frictionless API for overriding default styles.

Usually, I recommend having your components be styled via both style and className props.

For example:

Press + to interact
// this should work.
<MyComponent style={{name: "value"}} />
// and this.
<MyComponent className="my-class-name-with-dope-styles" />

Now, our goal isn’t just styling the component, but to make it as reusable as possible. This means letting the consumer style the component whichever way they want, whether that be using inline styles via the style prop, or by passing some className prop.

Styling the Header Component

Let’s begin with the Header child component; have a look at Header.js. ...

Access this course and 1400+ top-rated courses and projects.