Skip to content

Simple question about mapProps #1

@rhernandog

Description

@rhernandog

Hi Tim,

First thanks for the course, I've been watching it on egghead and checking the recompose repo learning from the API docs as well. In fact I landed in this repo from this particular issue on recompose:

acdlite/recompose#337

Unfortunately there are some advanced ES2015+ concepts that I haven't grasped completely yet, this question stems from that fact and a lack of real examples in the recompose docs.

The fact is that I don't quite understand why the arguments in the mapper must go between curly braces:

const filterByStatus = mapProps(
  ({users, status})=>({
    status,
    users: users.filter(u => u.status === status)
  })
);
// then create the new component using the base
const ActiveUser = filterByStatus(UserList);

// finally on the main <App /> component
<ActiveUser users={users} status="active" />

I get that the users and status are props of the base component, so we need to wrap them between curly braces in order to access them like this?:

props.status
props.users

In the same subject, could it be possible, since the params passed to the mapper are all the props passed to the <ActiveUser /> component, could it be possible to just spread the props on the mapper function?

const filterByStatus = mapProps(
  ({...props})=>({
    status,
    users: users.filter(u => u.status === status)
  })
);

Thanks again for the lessons and in advance for any answer or tip to become a better coder.

Best,
Rodrigo.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions