Enter Your Email Address to Watch This Lesson

Your link to unlock this lesson will be sent to this email address.

Unlock this lesson and all 833 of the free egghead.io lessons, plus get React content delivered directly to your inbox!



Existing egghead members will not see this. Sign in.

Just one more step!

Check your inbox for an email from us and click link to unlock your lesson.



Radium: Updating Button Styles via Props

0:47 React lesson by

In a CSS library like Bootstrap we can set a button's style to be "primary" or "secondary" by appending classes. For React components we want to be able to do this via props. Radium enables this by composing styles via an array. This mimicks the cascade of CSS.

Get the Code Now
click to level up

egghead.io comment guidelines

Avatar
egghead.io

In a CSS library like Bootstrap we can set a button's style to be "primary" or "secondary" by appending classes. For React components we want to be able to do this via props. Radium enables this by composing styles via an array. This mimicks the cascade of CSS.

Let's say we want to make our button blue, only if it's a primary button. Otherwise, it will be gray. First, we rename our style object to styles and nest our existing rules into the base property. Then, update the style prop.

Now, we can add a primary property and set the background color to blue and the base color to gray. Radium allows us to compose styles using array. It does this by doing a deep merge of properties. Because primary comes after base and the array, its properties will have precedence over those in base.

In this case, our button turns from gray to blue. Now, we want to make the color conditional on the kind of button. Add in the kind prop, define the condition. Now, we can toggle the button's color via the props.



HEY, QUICK QUESTION!
Joel's Head
Why are we asking?