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

Level Up!

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


    Show React Transition Group Elements with an Initial Transition with the `appear` Prop


    In React Transition Group, it can be a common situation for a transition to appear when the component renders, rather than wait for any state to change based on, for example, a button click. Should we want the component to show on mounting, instead of waiting for any state to change, we can make use of the appear prop, which adds two targetable classnames; *-appear and *-appear-active.



    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




    Instructor: Here, we have a button which toggles a menu component, and this is controlled with a CSS transition which is using a balloon transition, controlled by the enter, enter-active, exit, and exit-active selectors in the CSS.

    Let's say we wanted this menu to show initially when the page loads, so before the user clicks the button. We can just change the stateful show-balloon value to true. Then when we refresh the page, the menu shows instantly, but there's no transition on it.

    We can achieve a transition initially with the appear prop. In the CSS transition component, we can pass appear as true. What that's going to do is add an extra pair of class names onto this menu on the initial load.

    Then we can head over to our CSS, and include balloon-appear and balloon-appear-active, which will share the same styles as enter and enter-active. Now, when the page loads, we get the initial transition.