Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
Become a member
to unlock all features

    Radium: Updating Button Styles via Props

    Phil HoldenPhil Holden

    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.



    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson


    00:00 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.

    00:13 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.

    00:30 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.