Skip to content

Latest commit

 

History

History
30 lines (20 loc) · 498 Bytes

id.md

File metadata and controls

30 lines (20 loc) · 498 Bytes

id

id is the identity function.

const id = state => state;

It can be used with pick to create selectors by-id.

const getPostById = pick`posts.byId.${id}`;

Instead of:

const getPostById = pick`posts.byId.${x => x}`;

Or a no-no:

const getPostById = postId => pick`posts.byId.${postId}`;

P.S. The last example is "bad" because it will compile a new selector on every getPostById invocation, whereas the two above will compile only once.