Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple question about mapProps #1

Open
rhernandog opened this issue May 25, 2017 · 0 comments
Open

Simple question about mapProps #1

rhernandog opened this issue May 25, 2017 · 0 comments

Comments

@rhernandog
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant