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.


    Flatten a Prop using Recompose


    Learn how to use the ‘flattenProp’ higher order component to take a single object prop and spread each of its fields out as a prop.



    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




    I have this example where I've connected this user component to a fake Redux state. I'm mapping the user portion of the state into my component as the user prop and I'm printing it on the screen with and user.status.

    I'd like to be able to flatten it out so that I can ask for name and status as their own props, so I'll delete user. in both these instances.

    I can take this connect call and move it into a new higher-order component where I'll compose the connect call and a usage of flattened prop. Flattened prop just takes one param, the name of the prop that you'd like to flatten. In this case, it's going to be user.

    When I use my new higher-order component here, it's going to, first, connect to the Redux state and pull out the user, and then it's going to take that user and flatten it out so that all of its fields are spread into my wrapped component. When I refresh, it works just as before.