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.
[00:00] 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 user.name and user.status.
[00:14] 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.
[00:26] 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.
[00:51] 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.
Member comments are a way for members to communicate, interact, and ask questions about a lesson.
The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io
Be on-Topic
Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.
Avoid meta-discussion
Code Problems?
Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context
Details and Context
Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!