Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Radium: Updating Button Styles via Props


    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 Pro 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
    orLog In




    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.